Drawnow without displaying all calculation results in command window

4 次查看(过去 30 天)
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?

采纳的回答

Orion
Orion 2014-11-12
编辑:Orion 2014-11-12
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

更多回答(2 个)

Matt
Matt 2014-11-12
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 个评论
Orion
Orion 2014-11-12
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

请先登录,再进行评论。


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

类别

Help CenterFile Exchange 中查找有关 Graphics Performance 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by