필터 지우기
필터 지우기

Delete columns of matrices in a cell array

조회 수: 3 (최근 30일)
Neil
Neil 2013년 2월 21일
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.

채택된 답변

Wayne King
Wayne King 2013년 2월 21일
편집: Wayne King 2013년 2월 21일
B = cellfun(@(x) x(:,[1 3]),A,'uni',0);
or
C = cellfun(@(x) x(:,1:2:end),A,'uni',0);
  댓글 수: 1
Neil
Neil 2013년 2월 21일
Thanks. Simple enough. My matrices are actually quite large so I guess the second approach is more practical.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Azzi Abdelmalek
Azzi Abdelmalek 2013년 2월 21일
A={rand(3) rand(3) rand(3)}
cellfun(@(x) x(:,[1 3]),A,'un',0)

카테고리

Help CenterFile Exchange에서 Multidimensional Arrays에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by