Effacer les filtres
Effacer les filtres

How can I extract specific columns of a Matrix

1 vue (au cours des 30 derniers jours)
ghazale
ghazale le 29 Oct 2013
Modifié(e) : Cedric le 29 Oct 2013
For example I have this matrix
A = [1 0 0 0;0 0 0 0;0 1 0 0;0 0 0 0]
I want just extract the columns that they have one, (in this matrix will be column 1 and 2), and then show it in another matrix. I want to do this function for a big matrix. so the question must be d = [1 0;0 0;0 1;0 0]
Thanks

Réponses (1)

Cedric
Cedric le 29 Oct 2013
Modifié(e) : Cedric le 29 Oct 2013
Here is an example
>> A = [1 0 0 0;0 0 0 0;0 1 0 0;0 0 0 0]
A =
1 0 0 0
0 0 0 0
0 1 0 0
0 0 0 0
>> colId = any(A, 1)
colId =
1 1 0 0
>> d = A(:,colId)
d =
1 0
0 0
0 1
0 0
Putting all that together, you would perform the following operation:
>> d = A(:,any(A,1)) ;

Catégories

En savoir plus sur Cell 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!

Translated by