Updating textbox with variable

22 visualizzazioni (ultimi 30 giorni)
George Head
George Head il 1 Mag 2020
Risposto: Geoff Hayes il 1 Mag 2020
So i have plot that i want to connect a textbox to, so the textbox counts how many steps the person has done. The plot is a live, updating plot and i need the textbox to do the same. The format im after is "Steps: (no. steps)" which will be adding one each time. Here is the code im currently using although it doesnt work.
while (toc<30) %Loop when Plot is Active will run until plot is closed
vx=readVoltage(a,'A0');
vy=readVoltage(a,'A1');
.........
steps = stepleftacc + steprightacc
set(plotGraph,'XData',time,'YData',data);
axis([0 time(count) -90 90]);
pause(delay);
annotation('textbox',[0.75, 0.1, 0.1, 0.1],'string', "steps:" + steps)
This gives a textbox however the changing variable 'steps' seems to rewrite over itself, any solutions ot fix this?
Thanks

Risposte (1)

Geoff Hayes
Geoff Hayes il 1 Mag 2020
George - if you want to just update the existing annotation (rather than creating a new one on each iteration of the while loop) then you need to store the handle to the annotation and then use it for the update. For example,
hAnnotation = annotation('textbox',[0.75, 0.1, 0.1, 0.1],'string', "");
hold on;
while (toc<30) %Loop when Plot is Active will run until plot is closed
vx=readVoltage(a,'A0');
vy=readVoltage(a,'A1');
%.........
steps = stepleftacc + steprightacc
set(plotGraph,'XData',time,'YData',data);
axis([0 time(count) -90 90]);
pause(delay);
set(hAnnotation, 'String', "steps:" + steps);
% etc.
end
We create the annotaiton object outside of the loop and then update it on each iteration.

Categorie

Scopri di più su Install Products in Help Center e File Exchange

Prodotti

Community Treasure Hunt

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

Start Hunting!

Translated by