How do I convert a cell array with different number of values to a matrix
3 views (last 30 days)
Show older comments
I have a 35 x 1 cell array with 1-4 values in each cell and I need it as a matrix, but can not use cell2mat since I get the error "Dimensions of arrays being concatenated are not consistent." I would like it to be in a 35x5 matrix where whenever there is no value NaN gets put in its place.
example of the data:
data=
[1.29807499999879,1.87899500000640,2.52443499999936,3.21212499999092]
[1.67457999999169,2.55133499999647,3.36126500001410]
[1.50860999998986,2.17478999999003,2.87679499998922,3.53232500000740]
[0.923160000005737,2.03993500000797,2.99197999999160,3.83654499999830]
[1.58325499997591,2.23166999997920,3.17826499999501,3.96327499998733]
[2.15001500002109,3.21335500001442]
[1.83572000000277,2.66472500000964,3.45304000002216]
0 Comments
Accepted Answer
David Hill
on 4 Jun 2020
for k=1:length(m)
m{k}=[m{k},repmat(nan,1,5-length(m{k}))];
end
m=cell2mat(m);
More Answers (0)
See Also
Categories
Find more on Data Type Conversion in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!