Initialize to Increase Efficiency of plot3 Animation in Loop
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Laurel Castillo
am 18 Dez. 2018
Kommentiert: Laurel Castillo
am 18 Dez. 2018
![plot.PNG](https://www.mathworks.com/matlabcentral/answers/uploaded_files/199297/plot.png)
One line is stationary. The moving line is drawn with the psm_xp1V set (4*4*10). In each loop, a set of 4*4 matrix is used to update the values of the line.
Here is my main. Basically I just load the data and put the animiation function in the loop.
psm_xp1V_data = load ('psm_xp1V.mat', 'psm_xp1V');
for i=1:10
psm_xp1V=psm_xp1V_data.psm_xp1V(:,:,i);
[frame_plot] = animation3(psm_xp1V);
end
The animatioin function. The Base line is constant. And the Tip line updates in each loop, according to the dataset.
function [frame_plot]=animation3(psm_xp1V)
figure(3); % BTW I added these two lines here to make the figure as an output of the function. Do I really have to do so?
frame_plot = figure(3); %
axis([-0.5 0.5 -0.5 0.5 -0.5 0.5]);
grid on;
view(3);
s=0.1;
cla;
%Base
Base = eye(4);
BaseO = Base(1:3,4);
BaseX = Base(1:3,1).*s;
plot3([BaseO(1) BaseX(1)+BaseO(1)], [BaseO(2) BaseX(2)+BaseO(2)], [BaseO(3) BaseX(3)+BaseO(3)], ...
'color', 'r', 'linewidth', 3);
hold on % And do I really need hold on?
%Tip
tip_x = psm_xp1V; %input
TipO = tip_x(1:3,4);
TipX = tip_x(1:3,1).*s;
plot3([TipO(1) TipX(1)+TipO(1)], [TipO(2) TipX(2)+TipO(2)], [TipO(3) TipX(3)+TipO(3)], ...
'color', 'r', 'linewidth', 3);
hold on
drawnow;
end
Can I increase the efficiency by adding another function to initialize the figure before the loop?
So we don't have to create and update the whole figure in each loop. Maybe just update the values for the moving line Tip in each loop.
Please advise.
0 Kommentare
Akzeptierte Antwort
Steven Lord
am 18 Dez. 2018
Don't call plot3 over and over, which will keep increasing the number of graphics objects present in the figure. Instead either use the animatedline function or use one of the techniques described in the "Animation Techniques" section on this documentation page.
3 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Animation 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!