cell2mat command not giving expected result
19 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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 Commenti
Risposte (1)
Jan
il 5 Giu 2022
Modificato: Jan
il 5 Giu 2022
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 Commenti
Vedere anche
Categorie
Scopri di più su Data Type Conversion in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!