문제

I have a set of rectangles in a figure. I'm tagging them by a rect_tag index, and I want to get an array (or cell array) which has the tags of clicked rectangles. The rectangles are generated by:

for i_nf=1:nRects
    rect_tag = ['rectangle_num_' num2str(i_nf)];
    rectangle('Position', rectanglesMat(i_nf,:), 'Tag', rect_tag, 'ButtonDownFcn', {@add_rectangle});
end

How do I define the add_rectangle function to accomplish this?

도움이 되었습니까?

해결책

Thanks, @sebastian. It wokred. For future reference, this is what worked:

function add_rectangle(src, event)
    a = get(src,'Tag')
   if evalin('base', 'exist(''tag_list'',''var'')')
      tag_list= evalin('base','tag_list');
   else 
      tag_list= {};
   end
   class(tag_list)
   tag_list{end+1} = {a}; % add the point
   assignin('base','tag_list',tag_list); % save to base
end
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top