plot same column from different matrices on the same figure

2 ビュー (過去 30 日間)
Nicolas
Nicolas 2015 年 11 月 11 日
コメント済み: Nicolas 2015 年 11 月 18 日
I have 2 matrices A and B both 9x5
I would like to simplify the loop
figure, hold on
for i = 1:5
scatter(A(:,i),B(:,i))
end
hold off
ta

採用された回答

Sudhanshu Bhatt
Sudhanshu Bhatt 2015 年 11 月 18 日
Hi Nicolas,
I understand that you want the same column number in two different matrices be plotted on a figure and then in the next iteration take the data points from the next column in both the matrices and plot them on the same figure?
The loop can be removed when working with PLOT function in MATLAB. PLOT can take matrices as an input argument. More information on the PLOT function can be found in the documentation link below:
Scenario 1: Use PLOT function and plot lines:
% Example
A = rand(9,5);
B = rand(9,5);
figure;
plot(A,B);
SCATTER function unfortunately does not take matrices as an input argument. So there is no way to remove the loop. More information on SACTTER function can be found in the documentation link below:
But in this case we can specify markers in PLOT function to get the same result:
Scenario 2: Use PLOT function with Markers
% Example with Markers
A = rand(9,5);
B = rand(9,5);
figure;
plot(A,B,'o');
More information on Markers can be found in the documentation link below: Specify Line Style, Colors and Markers
Hope this helps!
Thanks
Sudhanshu Bhatt
  1 件のコメント
Nicolas
Nicolas 2015 年 11 月 18 日
Thank you very much, that was very helpful!

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

その他の回答 (0 件)

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by