How can I extract specific columns of a Matrix
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
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
0 Kommentare
Antworten (1)
Cedric
am 29 Okt. 2013
Bearbeitet: Cedric
am 29 Okt. 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)) ;
0 Kommentare
Siehe auch
Kategorien
Mehr zu Cell Arrays finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!