Concatenation array with different dimensions
7 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
user20912
el 6 de Mayo de 2021
Comentada: Stephen23
el 7 de Mayo de 2021
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 comentario
Stephen23
el 7 de Mayo de 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
Respuesta aceptada
Mouhamed Niasse
el 7 de Mayo de 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)
Más respuestas (0)
Ver también
Categorías
Más información sobre Creating and Concatenating Matrices en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!