How do I create a 2 column matrix from my x and y data

228 ビュー (過去 30 日間)
James Bagnall
James Bagnall 2019 年 8 月 25 日
コメント済み: Sara Fawal 2020 年 6 月 25 日
I want to make a 2 column matrix for my x and y data which consists of 1000 datapoints, I have tried this and it replaces only one column:
x=[0 1 2 3 4 5];
y=[0 1 2 3 4 5];
A = zeros(1000,2);
A(:,2)=y;
A(:,1)=x;

採用された回答

Star Strider
Star Strider 2019 年 8 月 25 日
Your data as you posted them are row vectors. Create column vectors from them to create ‘A’ by either doing a simple transpose (use the .' operator, not '), or forcing them to be column vectors with the ‘(:)’ notation
Try this:
A = [x(:), y(:)]
That should work.
  3 件のコメント
Star Strider
Star Strider 2019 年 8 月 25 日
As always, my pleasure!
Sara Fawal
Sara Fawal 2020 年 6 月 25 日
Hello Star How can I apply your code in a loop for multiple parameters?
My 'X' vector is my time variable and does not change.
However the 'Y' vectors are my changing variables.
Ex: X= time
Y(1)=a
Y(2)=b
Y(3)=c
.......Y(n)=m
Please let me know. Thank you

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

その他の回答 (0 件)

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by