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?
0 个评论
采纳的回答
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
0 个评论
更多回答(2 个)
Matt
2014-11-12
1 个评论
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
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Graphics Performance 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!