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

조회 수: 3 (최근 30일)
Benutzer Name
Benutzer Name 2018년 8월 17일
댓글: majety 2018년 8월 17일
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 ?

채택된 답변

majety
majety 2018년 8월 17일
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
Benutzer Name
Benutzer Name 2018년 8월 17일
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 2018년 8월 17일
try to add 'clf', so that it clears your figure before you plot over it again.
pause(0.01);figure(1);clf;

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Graphics Performance에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by