【问题标题】:Modifying textbox string in MATLAB figure修改MATLAB图中的文本框字符串
【发布时间】:2013-09-25 01:57:51
【问题描述】:

我正在尝试使用 for 循环内的注释在 matlab 图中显示一些数据。所以对于第一次迭代它的工作文件,从第二次迭代开始,数据被覆盖。如下图所示。请告诉我如何清除以前的文本,以便在每次迭代中显示该迭代中产生的正确数据。 。

我的代码如下-

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

【问题讨论】:

  • 您可以使用set函数重置注释中的文本,而无需删除注释或清除之前的文本。看我的回答。这种方法也非常快速高效。

标签: matlab matlab-figure


【解决方案1】:

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

% 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

【讨论】:

    【解决方案2】:

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

    %# 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

    【讨论】:

    • 在注释中添加特定标签是什么意思
    • 查看 annotation() 调用的最后一个参数
    • 嗨,Aralo,但它不起作用......当我使用 Detele 时......它没有显示任何东西......
    猜你喜欢
    • 2018-03-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-07-15
    • 2016-12-24
    • 2018-05-20
    • 2018-08-04
    相关资源
    最近更新 更多