フィルターのクリア

Plotting a line between two points

16 ビュー (過去 30 日間)
Benedict Low
Benedict Low 2018 年 11 月 23 日
コメント済み: Star Strider 2018 年 11 月 23 日
Hi,
I am encountering a problem trying to plot a line between two points (x1, y1; x2, y2). I have a dataset with alternating columns of x- and y-coordinate data (e.g. in a 10 by 10 matrix), and I added two new columns (e.g. columns 11 and 12) whereby column 11 is the mean x-coordinate of columns 1, 3, 5, ... and column 12 is the mean y-coordinate of columns 2, 4, 6,...
A(:,11)=mean(A(:,1:2:9),2);
A(:,12)=mean(A(:,2:2:10),2);
I want to plot a line between each point and the average so I use this as an example:
plot([A(1,1) A(1,11)],[A(1,2) A(1,12)])
This should plot a line between the first x- and y-coordinate and the mean x- and y-coordinate of the first row. However, the error message that I am getting is
"Data must be a single matrix Y or a list of pairs X,Y"
The frustrating thing is I tried it with randomly generated integers e.g.
A=randi(100,10,10)
and it works, but on my dataset it doesn't. I also noticed that the numeric format of the two additional columns I created are different, and I wonder if that plays a part.
Any help is appreciated.
Thank you.

採用された回答

Star Strider
Star Strider 2018 年 11 月 23 日
You may need to transpose the (10x2) matrices for each column in order to plot them as you want.
Try this (for the first column of ‘A’):
figure
plot([A(:,1) A(:,11)]', [A(:,1) A(:,12)]')
  2 件のコメント
Benedict Low
Benedict Low 2018 年 11 月 23 日
Thank you @Star Strider. I took out columns 11 and 12 and did a repmat to make the two matrices the same size. Then transposing the data as you advised worked.
Star Strider
Star Strider 2018 年 11 月 23 日
As always, my pleasure.
The plot function works in mysterious ways.

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

その他の回答 (0 件)

カテゴリ

Help Center および File Exchange2-D and 3-D Plots についてさらに検索

タグ

製品


リリース

R2015b

Community Treasure Hunt

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

Start Hunting!

Translated by