Plotting every 2 columns as X,Y in a matrix

27 ビュー (過去 30 日間)
Eric  Valois
Eric Valois 2020 年 3 月 5 日
コメント済み: Eric Valois 2020 年 3 月 5 日
Hey everyone,
Bigginer matlab user here, so bare with me. I have a matrix that is 9011X54. I need to plot every 2 rows as (X,Y) onto the same graph and I know there has to be an easy way to do this just have no idea how.
Thanks!
Eric

採用された回答

Cam Salzberger
Cam Salzberger 2020 年 3 月 5 日
Hey Eric,
This is pretty simple. The key to making it even simpler is this line in the plot documentation:
"If X and Y are both matrices, then they must have equal size. The plot function plots columns of Y versus columns of X."
So we just need to form your matrix (call it A) into two matrices X and Y, with each line's data in a column.
AT = A.'; % Transpose A into column order
X = AT(:, 1:2:end); % Get every other column for X
Y = AT(:, 2:2:end); % Similar for Y
plot(X, Y)
I'm assuming that you actually meant your original matrix is 54 x 9011 (rows x columns), since otherwise there wouldn't be an even number of rows to pair for x and y. This will make 27 lines, which is doable. If you were making hundreds or thousands of lines, though, that would probably slow down your graphics system too significantly. Keep that in mind for the future.
-Cam
  1 件のコメント
Eric  Valois
Eric Valois 2020 年 3 月 5 日
thanks! this worked great

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

その他の回答 (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