Reputation: 1637
Hi I have a cell array which I want to convert to a matrix:
a = {'1.2'; '1.3'; '1.45'}
cell2mat(a)
Gives me the error:
Error using cat
CAT arguments dimensions are not consistent.
Error in cell2mat (line 84)
m{n} = cat(1,c{:,n});
Please help thank you!
Upvotes: 0
Views: 1825
Reputation: 30046
cell2mat
fails because it's expecting numeric elements in the cell array, to be placed in a matrix. You have character arrays, not numeric elements, so you need to use str2double
to convert them to doubles (the output is a matrix as desired).
a = {'1.2'; '1.3'; '1.45'};
out = str2double( a );
Upvotes: 4