MATLAB Answers

Convert Cell to Matrix

1 view (last 30 days)
ha ha
ha ha on 26 Jun 2019
Answered: madhan ravi on 26 Jun 2019
Let' say, I have cell_A: 5x1 cell
cell_A={ [] ; [1] ; [5]; [] ; [2]};
How can I convert it to be matrix? 5-by-1 matrix
result_matrix=[ []; 1; 5 ; [] ; 2 ];

  0 Comments

Sign in to comment.

Accepted Answer

madhan ravi
madhan ravi on 26 Jun 2019
As sir Walter mentioned already , you cannot have holes in matrices . So you could replace them with nans perhaps:
cell_A(cellfun('isempty',cell_A)) = {NaN};
Matrix = cell2mat(cell_A)

  0 Comments

Sign in to comment.

More Answers (1)

Walter Roberson
Walter Roberson on 26 Jun 2019
You cannot. Matrices cannot have "holes" in them.

  0 Comments

Sign in to comment.

Tags

No tags entered yet.