Drawnow without displaying all calculation results in command window
3 ビュー (過去 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!