How extract a submatrix out of a main matrix?
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I have a matrix A (50x2) and I want to extract a certain number of row observations that statisfies the condition where I output the rows that include '1' in column 2 along with another column that would state 'yes'. How can I do that?
The first column are the ID numbers and the second column would be a '1' for yes and a '0' for no.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/406870/image.png)
I understand that a for loop would be applicable here but I have tried out a couple which didnt work out in adding it an extra column displayed.
thanks.
0 commentaires
Réponse acceptée
Ameer Hamza
le 8 Nov 2020
Easy peasy
M_new = M(M(:,2)==1,:); % M is your n*2 matrix
Read about logical indexing: https://www.mathworks.com/company/newsletters/articles/matrix-indexing-in-matlab.html
2 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Multidimensional Arrays dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!