How do I change cell array to matrix?

This question has been asked several times but none of the answers have helped me so far.
I have a cell array, C, that is 5 x 6 with each cell being 1 x 1.
How do I get a resulting 5 x 6 matrix with all indices being treated as numbers? I have used cell2mat(C) but that just results in the error 'Dimensions of matrices being concatenated are not consistent.' Shouldn't this work since each cell is 1 x 1?

댓글 수: 3

Stephen23
Stephen23 2018년 5월 10일
@K: please upload your cell array in a .mat file, by clicking the paperclip button.
‘Shouldn't this work since each cell is 1 x 1?’
No.
Consider:
C = {{rand(2)}, {rand(3)}}
C =
1×2 cell array
{1×1 cell} {1×1 cell}
K
K 2018년 5월 10일
The actual cell array is much larger. But I attached it..

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

 채택된 답변

Star Strider
Star Strider 2018년 5월 10일

0 개 추천

The numbers are stored as character arrays, the reason the dimensions did not match.
Simply convert them to a numeric array:
N = str2double(A1)

댓글 수: 2

K
K 2018년 5월 10일
Thank you!
Star Strider
Star Strider 2018년 5월 10일
As always, my pleasure!

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Matrix Indexing에 대해 자세히 알아보기

제품

릴리스

R2016b

질문:

K
K
2018년 5월 10일

댓글:

2018년 5월 10일

Community Treasure Hunt

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

Start Hunting!

Translated by