Delete columns of matrices in a cell array

I have a 1x5 cell array ,A, and each cell contains a 3x3 matrix. I'm trying to delete the second column from the matrix in each cell without using a for loop. I thought the following code might work but it does not. Any one has a good solution? Thanks.
Code I tried:
cellfun(@(x)x(:,2)= [],A)
Error message: The expression to the left of the equals sign is not a valid target for an assignment.

 Respuesta aceptada

Wayne King
Wayne King el 21 de Feb. de 2013
Editada: Wayne King el 21 de Feb. de 2013
B = cellfun(@(x) x(:,[1 3]),A,'uni',0);
or
C = cellfun(@(x) x(:,1:2:end),A,'uni',0);

1 comentario

Neil
Neil el 21 de Feb. de 2013
Thanks. Simple enough. My matrices are actually quite large so I guess the second approach is more practical.

Iniciar sesión para comentar.

Más respuestas (1)

Azzi Abdelmalek
Azzi Abdelmalek el 21 de Feb. de 2013
A={rand(3) rand(3) rand(3)}
cellfun(@(x) x(:,[1 3]),A,'un',0)

Categorías

Más información sobre Operators and Elementary Operations en Centro de ayuda y File Exchange.

Preguntada:

el 21 de Feb. de 2013

Community Treasure Hunt

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

Start Hunting!

Translated by