Borrar filtros
Borrar filtros

How can I extract specific columns of a Matrix

1 visualización (últimos 30 días)
ghazale
ghazale el 29 de Oct. de 2013
Editada: Cedric el 29 de Oct. de 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

Respuestas (1)

Cedric
Cedric el 29 de Oct. de 2013
Editada: Cedric el 29 de Oct. de 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)) ;

Categorías

Más información sobre Cell Arrays en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by