Filter löschen
Filter löschen

Display Value in Text Box

32 Ansichten (letzte 30 Tage)
Allison Bushman
Allison Bushman am 5 Mär. 2019
Kommentiert: Rik am 5 Mär. 2019
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');

Akzeptierte Antwort

Rik
Rik am 5 Mär. 2019
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 Kommentare
Allison Bushman
Allison Bushman am 5 Mär. 2019
Thank you. How would I update the value as a point moves?
Rik
Rik am 5 Mär. 2019
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.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Graphics Object Properties finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by