在MATLAB图中修改文本框字符串

时间:2013-09-25 01:57:51

标签: matlab matlab-figure

我试图在for循环中使用注释在matlab图中显示一些数据。所以对于第一次迭代,它工作文件,从第二次迭代开始,数据就越来越多了。有些事情如下图所示。请您告诉我如何清除以前的文本,以便在每次迭代中显示该迭代中生成的正确数据。 here

我的代码是以下 -

fig3=figure;
for i=1:10
...
...
D=distance(a,b);
figure(fig3), imshow(result_images{i},'InitialMagnification', 'fit');
annotation('textbox',...
[0 0.45 0.35 0.1],...
'String',['Measured Distance=' num2str(D)],...
'FontSize',40,...
'FontName','Arial',...
'EdgeColor',[1 1 0.9],...
'Color',[0.84 0.16 0]);
end

2 个答案:

答案 0 :(得分:2)

最有效的解决方案是通过句柄重用注释:

% create the annotation and save its handle
h = annotation(...); % set all your formatting prefs with any string

for i=1:10,
    % do something to update D ...
    set(h,'String',['Measured Distance=' num2str(D)]); % fast and easy
end

答案 1 :(得分:1)

最简单的解决方案是在注释中添加特定标记。

%# create the annotation
annotation('textbox',...
[0 0.45 0.35 0.1],...
'String',['Measured Distance=' num2str(D)],...
'FontSize',40,...
'FontName','Arial',...
'EdgeColor',[1 1 0.9],...
'Color',[0.84 0.16 0],...
'Tag' , 'somethingUnique');

%# delete the annotation
delete(findall(gcf,'Tag','somethingUnique'))

参考:Delete annotation from figure