for文で得た値をplotしたい
83 views (last 30 days)
Show older comments
for文で0~3000回姿勢計算を行い、その一回ごとの結果をplotしてグラフにしたいのですが、どのように配列すればいいのでしょうか。
for i = 0 : 0.001 : 3
R = R + r *0.001
end
a=~;b=~;c=~;
上のa,b,cを3000ずつplotしたいです。
3 Comments
Hernia Baby
on 30 May 2021
返信ありがとうございます。
自分の勘違いで更新はwhile文にする必要があると思い込んでいました。
確認しましたが、for文でも可能でした。
プロットはhold on状態でなければ、for文内に組み込むことでプロット可能です。
hold onの場合は事前のプロットが保持されます。
遷移をゆっくり見たい場合は、回答に入れました通り、pause関数でしばらく次の計算を待つことができます。
Accepted Answer
Hernia Baby
on 30 May 2021
for文というよりwhile文のほうが便利かなと思い、サンプルコードを書きました。
刻み幅が0.001だと、plotがゆっくりなので0.01刻みにしています。
clear,clc,close all;
R = zeros(3,1);
cnt = 0;
while cnt <= 3
r = 0.001*[cnt 10^3*sin(2*pi*cnt) 20^3*cos(2*pi*cnt)]';
R = R + r;
for i = 1:3
subplot(3,1,i)
scatter(cnt,R(i));
xlim([0 3])
end
pause(0.001);
cnt = cnt + 0.01;
end
1 Comment
Hernia Baby
on 30 May 2021
今確認取ってみましたが、for文でも可能でした。
またplot3で3次元描写する方法も以下に示します。
clear,clc,close all;
R = zeros(3,1);
cnt = 0;
for j = 0:0.01:3
r = 0.001*[j 10^3*sin(2*pi*j) 20^3*cos(2*pi*j)]';
R = R + r;
plot3(R(1),R(2),R(3),'ro')
%{
% a,b,cのそれぞれで描写する場合
for i = 1:3
subplot(3,1,i)
scatter(cnt,R(i));
xlim([0 3])
end
%}
pause(0.001);
end
More Answers (0)
See Also
Categories
Find more on グラフィックス オブジェクトのプログラミング in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!