Problem using cell2mat
이전 댓글 표시
I have a 25 by 25 cell array. Each cell contains a 32 by 32 array of type double. When I use cell2mat MATLAB gives me the following error:
Error using cat
Dimensions of arrays being concatenated are not consistent.
Any ideas on how I can fix this issue?
I have MATLAB R2021a
댓글 수: 3
Without any other information, I'm going to assume that not all of the elements of the cell array contain arrays ot the expected size, as the error message states. If they were the same, then they should concatenate just fine:
% create 2x2 cell of 10x10 numeric arrays
A = rand(10,10,4);
C = reshape(num2cell(A,[1 2]),[2 2])
% convert back to a 20x20 numeric array
B = cell2mat(C);
size(B)
Alberto Paredes
2021년 10월 22일
편집: Alberto Paredes
2021년 10월 22일
DGM
2021년 10월 23일
I don't know what the spreadsheets have. If there are missing rows/columns, then handling that on import depends on how they're being imported and where/why the rows/columns are missing.
답변 (1개)
Sahil Jain
2021년 10월 18일
Hi. As mentioned by another community member, "cell2mat" works without errors for the scenario you described. I used the following code to recreate your scenario with the same dimensions (similar to the code used by @DGM) .
A = rand(32,32,25*25);
B = num2cell(A, [1 2]);
B = reshape(B, [25 25]);
C = cell2mat(B);
size(C)
For troubleshooting, you can start by checking if all the cells are indeed 32x32 arrays.
카테고리
도움말 센터 및 File Exchange에서 Spreadsheets에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!