How to select rows from an array?

136 vues (au cours des 30 derniers jours)
ANANTA BIJOY BHADRA
ANANTA BIJOY BHADRA le 12 Oct 2022
I have matrix of A . I need to select the 2nd, 4th and 6th row. How can I write that in MATLAB code?

Réponses (3)

Torsten
Torsten le 12 Oct 2022
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 le 12 Oct 2022
Modifié(e) : Adam Danz le 12 Oct 2022
See this page of the doc to learn about array indexing.
Hint: A(__,:) where the blank is a vector of row indicies.

ANANTA BIJOY BHADRA
ANANTA BIJOY BHADRA le 12 Oct 2022
I think I found out the way. It has to be something like this:
B=A([2, 4, 6], :)

Catégories

En savoir plus sur Matrix Indexing dans Help Center et File Exchange

Produits


Version

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by