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
  1 件のコメント
Image Analyst
Image Analyst 2015 年 12 月 12 日
You mgiht also look at animatedLine() or comet().

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeContour Plots についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by