for文で得た値をplotしたい
27 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Jun Ozaki
am 30 Mai 2021
Kommentiert: Hernia Baby
am 30 Mai 2021
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 Kommentare
Hernia Baby
am 30 Mai 2021
返信ありがとうございます。
自分の勘違いで更新はwhile文にする必要があると思い込んでいました。
確認しましたが、for文でも可能でした。
プロットはhold on状態でなければ、for文内に組み込むことでプロット可能です。
hold onの場合は事前のプロットが保持されます。
遷移をゆっくり見たい場合は、回答に入れました通り、pause関数でしばらく次の計算を待つことができます。
Akzeptierte Antwort
Hernia Baby
am 30 Mai 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 Kommentar
Hernia Baby
am 30 Mai 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
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Annotations finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!