Does cell2mat work in Matlab 2019?

조회 수: 3 (최근 30일)
Coraline
Coraline 2021년 3월 1일
편집: Stephen23 2021년 3월 2일
I try to covert a matrix with numbers (in a cell) to a double matrix. This is the erro I get.
The issue seems to be the curly brakets used in line 36 of cell2mat? I tried to change it and it turns out it is 'read only'.
Brace indexing is not supported for variables of this type.
Error in cell2mat (line 36)
if isnumeric(c{1}) || ischar(c{1}) || islogical(c{1}) ||
isstruct(c{1})
  댓글 수: 1
Stephen23
Stephen23 2021년 3월 2일
편집: Stephen23 2021년 3월 2일
"The issue seems to be the curly brakets used in line 36 of cell2mat? I tried to change it and it turns out it is 'read only'."
Do NOT change any files in the installation folder of any application (i.e. under Program Files, etc). If you change these files you are likely to introduce bugs and incompatibilities which are then almost impossible to locate or repair.
The issue is actually that you are calling cell2mat on a numeric array.

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

답변 (1개)

ANKUR KUMAR
ANKUR KUMAR 2021년 3월 1일
It is working well for me.
C = {[1], [2 3 4];
[5; 9], [6 7 8; 10 11 12]}
A = cell2mat(C)
1 2 3 4
5 6 7 8
9 10 11 12
Make sure you have the contents of cells in the same column must have the same number of columns, although they need not have the same number of rows. See this for your reference.
  댓글 수: 4
Steven Lord
Steven Lord 2021년 3월 1일
A isn't a cell array. If you want to convert the other way, turn a matrix into a cell array, use mat2cell.
ANKUR KUMAR
ANKUR KUMAR 2021년 3월 1일
편집: ANKUR KUMAR 2021년 3월 1일
If you wish to convert cell to mat, input should be in a cell format.
A={[ 3 -3 -3 4; 4 -2 3 4; -6 -3 -3 -2; 5 5 5 4]}
cell2mat(A)
There is no point to save single matrix in cell, and then use cell2mat to again get back to matrix from cell, unless you wish to play with matlab.
Indexing is supporting in cell2mat, but for that, input data should have an index. A regular matrix does not have an index of its own. It has the indices of its elements.
Hope it clears.

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

카테고리

Help CenterFile Exchange에서 Data Type Conversion에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by