Drawnow without displaying all calculation results in command window
4 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
Akzeptierte Antwort
Orion
am 12 Nov. 2014
Bearbeitet: Orion
am 12 Nov. 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
0 Kommentare
Weitere Antworten (2)
Matt
am 12 Nov. 2014
1 Kommentar
Orion
am 12 Nov. 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
Siehe auch
Kategorien
Mehr zu Graphics Performance finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!