![untitled.png](https://www.mathworks.com/matlabcentral/answers/uploaded_files/199353/untitled.png)
2つの点同士を線で結ぶ方法はありますか。点の座標は実験結果なので11×1の行列(点Qはqkakudo_x,qkakudo_y)(点Wはwkakudo_x,wkakudo_y)としてワークスペースに変数として格納しています。このときの点Qのn行列目と点Wのn行列目同士(1<n<11)を結ぶ方法を教えてください。
298 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Akzeptierte Antwort
Kazuya
am 19 Dez. 2018
点と点を結ぶ「ツール」はありませんが、プロットを書くならいろいろ方法があります。3つ紹介しますが、どれも同じ結果になります。
まず、プロットするサンプルデータ用意しますが、ワークスペースに入力済というデータと同じように 11x1 のベクトルとします。
N = 11;
p_x = rand(N,1);
p_y = rand(N,1);
q_x = rand(N,1);
q_y = rand(N,1);
方法1
もっとも実直な方法。。
figure(1)
for ii=1:N
plot([p_x(ii),p_y(ii)],[q_x(ii),q_y(ii)])
hold on
end
hold off
方法2
p_x と p_y、q_x と q_y をそれぞれ1つの変数にまとめただけです。 plot コマンド実行時の文字数が少し減る・・。
figure(2)
p_xy = [p_x, p_y];
q_xy = [q_x, q_y];
for ii=1:N
plot(p_xy(ii,:),q_xy(ii,:))
hold on
end
hold off
方法3
ちょっと理解が難しい構造ですが、、呼び出し方としては一番シンプルです。
figure(3)
plot(p_xy',q_xy')
2 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu ライン プロット 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!