Place zero in an empty matrix within cell array?

18 Ansichten (letzte 30 Tage)
Jones
Jones am 6 Sep. 2017
Kommentiert: James Tursa am 6 Sep. 2017
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.

Akzeptierte Antwort

James Tursa
James Tursa am 6 Sep. 2017
x(emptyCells) = {-1};
  2 Kommentare
Jones
Jones am 6 Sep. 2017
Ahhhh so simple, so effective. Thanks a lot!
James Tursa
James Tursa am 6 Sep. 2017
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.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Matrices and 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!

Translated by