Concatenation array with different dimensions

20 次查看(过去 30 天)
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 个评论
Stephen23
Stephen23 2021-5-7
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

请先登录,再进行评论。

采纳的回答

Mouhamed Niasse
Mouhamed Niasse 2021-5-7
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)

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息

产品


版本

R2019b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by