我在图中有一组矩形。我用rect_tag索引对它们进行标记,我想得到一个数组(或单元格数组),其中包含单击矩形的标记。矩形由生成
for i_nf=1:nRects
rect_tag = ['rectangle_num_' num2str(i_nf)];
rectangle('Position', rectanglesMat(i_nf,:), 'Tag', rect_tag, 'ButtonDownFcn', {@add_rectangle});
end
如何定义add_rectangle函数来实现这一点?
谢谢,@sebastian。哇。为了将来参考,这是行之有效的:
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