cell2mat command not giving expected result
15 次查看(过去 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!