Borrar filtros
Borrar filtros

Drawnow without displaying all calculation results in command window

1 visualización (últimos 30 días)
Hello,
I would like to know how can I use the DRAWNOW function more efficiently. I have a GUI with few axes there, and pressing a pushbutton starts calculations. At the end of these calculations (which involves a FOR loop as the main driven parameter), I am plotting the results which are matrices (eg. a pressure matrix VS time matrix plot).
However I would like to plot that in real time, but using the DRAWNOW function just before the end of the FOR loop is too slow:
for(i:0,0.01,100)
% My calculations here
axes(handles.axes26);
plot(timeM, pressureM, '-r');
grid on;
hold on;
plot(timeM, torqueM);
axes(handles.axes28);
plot(timeM, lengthM);
grid on;
axes(handles.axes25);
plot(timeM, sratioM);
axes(handles.axes29);
plot(timeM, alphaM);
drawnow;
end
Is there a more efficient and faster way to plot this in real time?

Respuesta aceptada

Orion
Orion el 12 de Nov. de 2014
Editada: Orion el 12 de Nov. de 2014
Hi,
You should decompose your code in 2 part. 1st part : create the graphic objcet at the first iteration 2nd part : update them after.
The creation of graphic object takes time. in your code, you are recreating all your graphics at each iteration.
do something like
for i=0:0.01:100
% My calculations here
if i==0
%%creation of the plot at the 1st iteration
axes(handles.axes26);
Hdl.pressureM = plot(timeM, pressureM, '-r');
grid on;
hold on;
Hdl.torqueM = plot(timeM, torqueM);
axes(handles.axes28);
Hdl.lengthM = plot(timeM, lengthM);
grid on;
axes(handles.axes25);
Hdl.sratioM = plot(timeM, sratioM);
axes(handles.axes29);
Hdl.alphaM = plot(timeM, alphaM);
else
%%update your plot at all other iterations
set(Hdl.pressureM,'Xdata',timeM,'Ydata',pressureM);
set(Hdl.torqueM,'Xdata',timeM,'Ydata',torqueM);
set(Hdl.lengthM,'Xdata',timeM,'Ydata',lengthM);
set(Hdl.sratioM,'Xdata',timeM,'Ydata',sratioM);
set(Hdl.alphaM,'Xdata',timeM,'Ydata',alphaM);
end
end

Más respuestas (2)

Matt
Matt el 12 de Nov. de 2014
Thank you for your answer!
It did the trick, I added a DRAWNOW at the end of the ELSE loop and it plots everything in real time at a reasonable speed. On a side note, it takes about 10 seconds to plot 0.1s of data, even tho the CPU usage is not 100%. Oh well I think I have to simplify my calculations a bit.
  1 comentario
Orion
Orion el 12 de Nov. de 2014
you don't have to plot at each iteration.
add a counter to plot at every 20 (change the value if you want) iteration.
count = 0;
for i=0:0.01:100
% My calculations here
% update the counter
count = count + 1;
if i==0
%%creation of the plot at the 1st iteration
axes(handles.axes26);
Hdl.pressureM = plot(timeM, pressureM, '-r');
grid on;
hold on;
Hdl.torqueM = plot(timeM, torqueM);
axes(handles.axes28);
Hdl.lengthM = plot(timeM, lengthM);
grid on;
axes(handles.axes25);
Hdl.sratioM = plot(timeM, sratioM);
axes(handles.axes29);
Hdl.alphaM = plot(timeM, alphaM);
else
if count == 20
count = 0;
%%update your plot at all other iterations
set(Hdl.pressureM,'Xdata',timeM,'Ydata',pressureM);
set(Hdl.torqueM,'Xdata',timeM,'Ydata',torqueM);
set(Hdl.lengthM,'Xdata',timeM,'Ydata',lengthM);
set(Hdl.sratioM,'Xdata',timeM,'Ydata',sratioM);
set(Hdl.alphaM,'Xdata',timeM,'Ydata',alphaM);
end
end
end

Iniciar sesión para comentar.


Matt
Matt el 12 de Nov. de 2014
Excellent, that is much better, again, thank you very much. I really like MATLAB and its community, you learn everyday!

Categorías

Más información sobre Graphics Performance en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by