Azzera filtri
Azzera filtri

Concatenation array with different dimensions

21 visualizzazioni (ultimi 30 giorni)
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 Commento
Stephen23
Stephen23 il 7 Mag 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

Accedi per commentare.

Risposta accettata

Mouhamed Niasse
Mouhamed Niasse il 7 Mag 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)

Più risposte (0)

Categorie

Scopri di più su Creating and Concatenating Matrices in Help Center e File Exchange

Prodotti


Release

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by