cell2mat command not giving expected result
조회 수: 16 (최근 30일)
이전 댓글 표시
Error using cat
Dimensions of arrays being concatenated are not consistent.
Error in cell2mat (line 83)
m{n} = cat(1,c{:,n});
Error in classification (line 12)
testing_data = cell2mat( tst_data ) ;
I'm getting the above error on trying to convert the 102x12 dimension cell type variable "tst_data" into a numeric matrix to be stored in testing_data. Tried checking if any of the elements are empty-arrays, hence resulting in the concatenating error. Ran the correction code to eliminate empty arrays nevertheless. Still the error persists. The code snippet calling cell2mat function is as follows:
isEm = cellfun( @isempty, tst_data ) ;
tst_data(isEm) = {NaN} ;
testing_data = cell2mat( tst_data ) ;
Can't figure out what the issue is or how to fix this. Would appreciate any help...
댓글 수: 0
답변 (1개)
Jan
2022년 6월 5일
편집: Jan
2022년 6월 5일
There are no empty array in the provided data, but the sizes of the vectors differ: all are row vectors, but they have between 16 and 21 elements. Then you cannot concatenate them to a matrix.
data = load('tsts_data.mat');
L = cellfun('size', data.tst_data, 2)
% 18 16 17 17 17 17 18 18 18 17 17 18
% 18 16 17 17 17 17 18 19 18 17 17 18
% 18 16 17 17 17 17 19 18 18 17 17 19
% 17 16 17 17 17 17 18 18 17 19 17 18
% 17 16 17 17 17 17 18 18 17 18 17 17
% 17 16 17 17 17 17 19 19 17 18 17 18
% 17 16 17 17 17 17 19 19 17 18 17 18
% ...
Replacing empty arrays by NaNs would not be useful, because the sizes still do not match.
What is the wanted output?
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Data Type Conversion에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!