A while loop to display a sequence of motion (like a rocket)

조회 수: 1 (최근 30일)
Christoffer Thornvall
Christoffer Thornvall 2015년 12월 8일
댓글: Image Analyst 2015년 12월 12일
I'm having some problems with this loop. I would want to display something similar to plot(0,k) one by one as an attempt to simulate a rocket launch.
k = [y(:,2)];
noT=size(k,1);
clf;
clear MV;
for ti=1:noT
hold off;
plot(0,k(ti,:),'k-')
axis('image');
pause(0.1)
axis('off');
MV(ti)=getframe;
end;
where size(k,1) is 200 and k ranges from 0.006400000000000E6 to 8.553552443483490E6
Any ideas?
Regards, Christoffer
  댓글 수: 1
Image Analyst
Image Analyst 2015년 12월 12일
I don't understand why you're having just a single x value, zero, as your x array, and not an array that is the same length as k(ti,:). Can you give us any values for y?

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

답변 (1개)

Image Analyst
Image Analyst 2015년 12월 12일
Try this:
y = rand(10, 2); % Sample data.
k = y(:,2);
numberOfT = size(k,1);
clf;
clear('MV');
for ti = 1 : numberOfT
plot(1:ti, k(1:ti), 'k*-', 'LineWidth', 2, 'MarkerSize', 15)
caption = sprintf('k vs. ti, for max ti = %d', ti);
title(caption, 'FontSize', 20);
xlabel('ti', 'FontSize', 20);
ylabel('k', 'FontSize', 20);
grid on;
drawnow;
if ti == 1
% Set up figure properties:
% Enlarge figure to full screen.
set(gcf, 'Units', 'Normalized', 'OuterPosition', [0 0 1 1]);
% Get rid of tool bar and pulldown menus that are along top of figure.
set(gcf, 'Toolbar', 'none', 'Menu', 'none');
% Give a name to the title bar.
set(gcf, 'Name', 'Demo by ImageAnalyst', 'NumberTitle', 'Off')
end
pause(0.1)
% MV(ti)=getframe;
end

카테고리

Help CenterFile Exchange에서 Contour Plots에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by