Effacer les filtres
Effacer les filtres

Display Value in Text Box

32 vues (au cours des 30 derniers jours)
Allison Bushman
Allison Bushman le 5 Mar 2019
Commenté : Rik le 5 Mar 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');

Réponse acceptée

Rik
Rik le 5 Mar 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 commentaires
Allison Bushman
Allison Bushman le 5 Mar 2019
Thank you. How would I update the value as a point moves?
Rik
Rik le 5 Mar 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.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Graphics Object Properties dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by