Concatenation array with different dimensions

7 ビュー (過去 30 日間)
user20912
user20912 2021 年 5 月 6 日
コメント済み: Stephen23 2021 年 5 月 7 日
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 Center および File ExchangeCreating 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