Real time counter plot

Hi. I am using appdesigner to create a counter. I am trying to plot the values that will be stored in the variable app.Counter in real-time. If the value is increased or decreased the plot must display this with a marker and a line joining from the previous marker. By pressing the pushbutton the app.Counter value is incremented by 1 but I am not seeing anything plotted on the UIAxes. Please assist.
function ButtonPushed(app,event)
app.Counter=app.Counter+1;
app.EditField.Value=app.Counter;
plot(app.UIAxes,app.Counter)
end

3 comentarios

dpb
dpb el 30 de Sept. de 2022
A single default point is likely simply to not be visible --
plot(app.UIAxes,app.Counter,'xk')
should show a black "x" at the x axis value of 1.
Lola
Lola el 1 de Oct. de 2022
This plots an "x" only on x axis=1. When the count value increases I would like the x-axis value to increase as well. For example when the count is increased there should be another "x" marker added to the plot to show the increase. Is it possible to do this and have a line join the points when the count is being changed
dpb
dpb el 1 de Oct. de 2022
I figured something was up...for that look at animatedline and addpoints

Iniciar sesión para comentar.

Respuestas (1)

Image Analyst
Image Analyst el 1 de Oct. de 2022

0 votos

Try making an array like
function ButtonPushed(app,event)
if a.Counter == 0
allCounts = 0;
else
app.Counter=app.Counter+1;
allCounts(end+1) = app.Counter
end
x = 0; % Vertical x's, OR:
x = 0 : app.Counter; % If you want each x in its own column.
app.EditField.Value=app.Counter;
plot(app.UIAxes,x, allCounts, 'kx-', 'LineWidth', 2, 'MarkerSize', 18);
end

5 comentarios

Lola
Lola el 1 de Oct. de 2022
Hi @Image Analyst. I've tried this code but MATLAB throws the error 'Vectors must be the same size' in the line
plot(app.UIAxes,x, allCounts, 'kx-', 'LineWidth', 2, 'MarkerSize', 18);
Lola
Lola el 1 de Oct. de 2022
There is no size. The counter will start from zero and increment from its current value when the button is pushed
Image Analyst
Image Analyst el 1 de Oct. de 2022
Lola, come on. There is a size. It even told you so. Please invest 2 hours here:
You can find out the sizes in the workspace panel, or by doing this:
size(x)
size(app.Counter)
size(allCounts)
dpb
dpb el 1 de Oct. de 2022
Editada: dpb el 1 de Oct. de 2022
...
x = 0 : app.Counter; % If you want each x in its own column.
should be
x = 0 : app.Counter-1; % If you want x on plot to begin at 0
x = 1 : app.Counter; % If you want x on plot to begin at 1
to account for "off-by-one" error of 1-based arrays and beginning the count with zero instead of one...
This should be easy to verify is the issue with the debugger as @Image Analyst suggested, presuming you used the vector multiple-x option...
However, this would be much simpler with animatedline and addpoints as suggested earlier; no array needed although would need to create the handle to the animated line to begin with on startup/initialization.

Iniciar sesión para comentar.

Categorías

Más información sobre Creating, Deleting, and Querying Graphics Objects en Centro de ayuda y File Exchange.

Preguntada:

el 30 de Sept. de 2022

Editada:

dpb
el 1 de Oct. de 2022

Community Treasure Hunt

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

Start Hunting!

Translated by