How to select rows from an array?

I have matrix of A . I need to select the 2nd, 4th and 6th row. How can I write that in MATLAB code?

回答 (3 件)

ANANTA BIJOY BHADRA
ANANTA BIJOY BHADRA 2022 年 10 月 12 日

1 投票

I think I found out the way. It has to be something like this:
B=A([2, 4, 6], :)

1 件のコメント

Casey
Casey 2024 年 5 月 8 日
Thank you for posting, this was helpful.

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

Torsten
Torsten 2022 年 10 月 12 日

0 投票

B = [A(2,:);A(4,:);A(6,:)]
or if you want the rows one by one:
A2 = A(2,:);
A4 = A(4,:);
A6 = A(6,:);
Adam Danz
Adam Danz 2022 年 10 月 12 日
編集済み: Adam Danz 2022 年 10 月 12 日

0 投票

See this page of the doc to learn about array indexing.
Hint: A(__,:) where the blank is a vector of row indicies.

カテゴリ

ヘルプ センター および File ExchangeMatrix Indexing についてさらに検索

製品

リリース

R2021a

タグ

質問済み:

2022 年 10 月 12 日

コメント済み:

2024 年 5 月 8 日

Community Treasure Hunt

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

Start Hunting!

Translated by