Display Value in Text Box

61 ビュー (過去 30 日間)
Allison Bushman
Allison Bushman 2019 年 3 月 5 日
コメント済み: Rik 2019 年 3 月 5 日
I am trying to display the value of a in a text box.
a=trapz(cP6-cP7);
str='Area Swept: %d';
annotation('textbox',[0.3 0.5 0.3 0.3],'String',str,'FitBoxToText','on');

採用された回答

Rik
Rik 2019 年 3 月 5 日
You need to transform your value to text using either sprintf or num2str:
a=trapz(cP6-cP7);
str=sprintf('Area Swept: %d',a);
annotation('textbox',[0.3 0.5 0.3 0.3],'String',str,'FitBoxToText','on');
  2 件のコメント
Allison Bushman
Allison Bushman 2019 年 3 月 5 日
Thank you. How would I update the value as a point moves?
Rik
Rik 2019 年 3 月 5 日
You can store a handle to the annotation object in a variable, after which you can modifiy the properties as you need to.
%example:
a=10;
figure(1),clf(1)%clear figure (use only for debugging)
str=sprintf('Area Swept: %d',a);
h_annot=annotation(...
'textbox',[0.3 0.5 0.3 0.3],...
'String',str,...
'FitBoxToText','on');
for n=1:10
%move it around randomly
set(h_annot,...
'position',[0.1+rand/5 0.4+rand/5 0.3 0.3],...
'FitBoxToText','on')
pause(1/3)
end
If my answer solved your problem, please consider marking it as accepted answer.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeGraphics Object Properties についてさらに検索

タグ

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by