Pulling a column from a matrix to a vector

1 回表示 (過去 30 日間)
Alexander Ketzle
Alexander Ketzle 2021 年 11 月 12 日
コメント済み: Star Strider 2021 年 11 月 12 日
I have a data set
1 0.318524 5
2 0.534064 4
3 0.0899507 3
4 0.111706 2
5 0.136293 1
That I'm trying to pull the individual columns out of to turn into vectors, after scanning the file and putting the data into a matrix. I want the result to be something along the lines of
vector1 = [1,2,3,4,5];
vector2 = [0.318524,0.534064,0.0899507,0.111706,0.136293];
vector3 = [5,4,3,2,1];
Thank you.

採用された回答

Star Strider
Star Strider 2021 年 11 月 12 日
Try this —
M = [1 0.318524 5
2 0.534064 4
3 0.0899507 3
4 0.111706 2
5 0.136293 1];
vector1 = M(:,1)
vector1 = 5×1
1 2 3 4 5
And so for the rest.
However, I caution that as a general rule, it is best not to create individulal vectors, and instead simply index into the matrix, as needed.
.
  2 件のコメント
Alexander Ketzle
Alexander Ketzle 2021 年 11 月 12 日
Exactly what I was looking for, thank you!
Star Strider
Star Strider 2021 年 11 月 12 日
As always, my pleasure!
.

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

その他の回答 (0 件)

カテゴリ

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

製品


リリース

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by