Azzera filtri
Azzera filtri

plot the recent data with drawnow in level-2 matlab file s-function

4 visualizzazioni (ultimi 30 giorni)
Hello,
I plot a flat surface and rotate it with "drawnow" in a figure. I used to do this in a "level-2 matlab file s-function" for my Simulink simulation. It works in principal , but the figure updates the recent plot every t_out. It is like I would use the "hold on" command in a normal script. After some time its just a cylinder because Matlab saves every plot. How can I get only the recent plot in the figure, like a flat surf who rotates ?

Risposta accettata

majety
majety il 17 Ago 2018
You can number the figure as figure(1) and keep plotting your circle to the same figure. Make sure you get the length of your axes right so that the animation looks good. Also remember that you can use "hold off" if you don't want a cylinder from your piled up circles.
Example:
for theta = 0:pi/50:2*pi;
x = 20 *cos(theta);
y = 20*sin(theta);
originx = 0;
originy = 0;
pause(0.01);figure(1);
plot([x,originx],[y,originy],'b','LineWidth',2);hold on;
plot(x,y,'k+','LineWidth',2);hold off;
xlim([-30,30]);ylim([-30,30]);
end
  2 Commenti
Benutzer Name
Benutzer Name il 17 Ago 2018
I tried it with my code but it doesn't work. You see the what's wrong?!
for x=0:pi/160:pi
pts = [4 -4 -4 4 ;
4 4 -4 -4 ;
0 0 0 0 ;
1 1 1 1 ];
axis equal
xlim([-10 10])
ylim([-10 10])
zlim([-10 10])
pause(0.01)
figure(1)
h1 = patch('FaceColor',[0.3010 0.7450 0.9330]);hold on;
h1.XData = pts(1,:) ./ pts(4,:);
h1.YData = pts(2,:) ./ pts(4,:);
h1.ZData = pts(3,:) ./ pts(4,:);
set(gca,'view',[30 30])
mrot = makehgtform('xrotate',x,'yrotate',0,'zrotate',0)
p2 = mrot*pts;
h2 = patch('FaceColor',[0.9290 0.6940 0.1250]);hold off;
h2.XData = p2(1,:) ./ p2(4,:);
h2.YData = p2(2,:) ./ p2(4,:);
h2.ZData = p2(3,:) ./ p2(4,:);
end
majety
majety il 17 Ago 2018
try to add 'clf', so that it clears your figure before you plot over it again.
pause(0.01);figure(1);clf;

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Graphics Objects in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by