How to make a column of cells into array? Each cell in a row when made into an array would a row with different number of columns
2 次查看(过去 30 天)
显示 更早的评论
Can I also ask, how can I make into arrays a column of cell files?
timeatstayandtripcomp=Scenario1_indvoutputagg(1:r,88); %each row of the cell represents the variable for each ID
timeatstayandtripcomp=cell2mat(timeatstayandtripcomp);
I'd like each row in there to be an array. I've tried cell2mat but get Error using cat; I think it's because the number of columns for each row isn't necessarily the same.
I could maybe do a for loop, but I need to repeat this for many variables, so I'm wondering if there's a more efficient way of doing it
![Capture.JPG](https://www.mathworks.com/matlabcentral/answers/uploaded_files/270301/Capture.jpeg)
0 个评论
采纳的回答
Stephen23
2020-2-6
编辑:Stephen23
2020-2-6
Download Jos's padcat:
and use it like this:
M = padcat(Scenario1_indvoutputagg{1:r,88})
3 个评论
Stephen23
2020-2-7
"Is there a coding way of doing this though?"
Sure: measure the sizes of the vectors, preallocate an output array to fit the largest vector, then use a loop to assign each of the vectors to that array. It will be quite efficient and is trivial to implement.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Parallel and Cloud 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!