Place zero in an empty matrix within cell array?

조회 수: 18 (최근 30일)
Jones
Jones 2017년 9월 6일
댓글: James Tursa 2017년 9월 6일
I have a cell array (x) where in this case there is no value in one of the cell matrix. I want to add a -1 value in the matrix as a way of 'place-holding' that column. I've tried these approaches:
emptyCells = cellfun('isempty',x);
x(emptyCells) = -1;
x(isnan([x{:}]))={-1}
x(cellfun(@isnan,x))={-1}
Any help would be greatly appreciated.

채택된 답변

James Tursa
James Tursa 2017년 9월 6일
x(emptyCells) = {-1};
  댓글 수: 2
Jones
Jones 2017년 9월 6일
Ahhhh so simple, so effective. Thanks a lot!
James Tursa
James Tursa 2017년 9월 6일
Basically, since x is a cell array, any subset of it using parentheses like x(whatever) is also a cell array, which means the right hand side needs to be a cell array also for the assignment to work like you want.

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

추가 답변 (0개)

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by