Concatenation array with different dimensions
7 views (last 30 days)
Show older comments
I got a cell with data as:
whos dv1
dv1 1x5
and the elements are of different size:
dv1 =
1x5 cell array
Columns 1 through 5
{86x1 double} {83x1 double} {79x1 double} {84x1 double} {84x1 double}
I need to concatenate in the second dimension so I get all elements from this cell side by side. Since the dimensions are not the same, I can't do this.
I thought to take the max value and create a empty variable:
temp = zeros(86,5)
And then try to fill it with the cell values but i wasn't able to do it.
So, how can I concatenate this kind of cell?
1 Comment
Stephen23
on 7 May 2021
You do not need two loops. Here is a more robust approach without any hard-coded sizes:
nmr = max(cellfun(@numel,dv1));
out = cell(nmr,numel(dv1));
for k = 1:numel(dv1)
tmp = dv1{k};
out(1:numel(tmp),k) = tmp;
end
Accepted Answer
Mouhamed Niasse
on 7 May 2021
try this
temp=zeros(86,5);
for i=1:5
k=max(size(dv1{1,i}));
for ii=1:k
temp(ii,i)=dv1{1,i}(ii);
end
end
disp(temp)
More Answers (0)
See Also
Categories
Find more on Creating and Concatenating Matrices 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!