How i can combine three or more than three matrix?

1 visualización (últimos 30 días)
Akash Pal
Akash Pal el 10 de Ag. de 2021
Editada: Stephen23 el 10 de Ag. de 2021
y=[repmat(x1,size(x2,1),1),repelem(x2,size(x1,1),1)];
I am writing this code for combining two matrix where the row number is different but column is same .
My question is how i can combine more than two matrix where their row number is differnt but column is same ?

Respuesta aceptada

Stephen23
Stephen23 el 10 de Ag. de 2021
Editada: Stephen23 el 10 de Ag. de 2021
Note that you will run out of memory very quickly as you increase the number of matrices.
format compact
inp = {rand(3,4),rand(4,4),rand(5,4)}; % all matrices in one cell array.
celldisp(inp)
inp{1} = 0.3652 0.5458 0.7328 0.9886 0.1774 0.4146 0.6908 0.7239 0.5397 0.1625 0.8757 0.0996 inp{2} = 0.4526 0.4298 0.2415 0.8247 0.5996 0.3380 0.2754 0.7322 0.2394 0.6964 0.4858 0.6903 0.1400 0.8696 0.7921 0.3204 inp{3} = 0.3385 0.7161 0.8820 0.6369 0.9931 0.9668 0.0144 0.1382 0.8860 0.5127 0.3950 0.9405 0.0639 0.5230 0.1287 0.5097 0.7254 0.0057 0.9713 0.4787
fun = @(m)1:size(m,1);
idr = cellfun(fun,inp,'uni',0);
[idr{:}] = ndgrid(idr{:}); % comma-separated lists
baz = @(m,r)m(r(:),:);
tmp = cellfun(baz,inp,idr,'uni',0);
out = horzcat(tmp{:})
out = 60×12
0.3652 0.5458 0.7328 0.9886 0.4526 0.4298 0.2415 0.8247 0.3385 0.7161 0.8820 0.6369 0.1774 0.4146 0.6908 0.7239 0.4526 0.4298 0.2415 0.8247 0.3385 0.7161 0.8820 0.6369 0.5397 0.1625 0.8757 0.0996 0.4526 0.4298 0.2415 0.8247 0.3385 0.7161 0.8820 0.6369 0.3652 0.5458 0.7328 0.9886 0.5996 0.3380 0.2754 0.7322 0.3385 0.7161 0.8820 0.6369 0.1774 0.4146 0.6908 0.7239 0.5996 0.3380 0.2754 0.7322 0.3385 0.7161 0.8820 0.6369 0.5397 0.1625 0.8757 0.0996 0.5996 0.3380 0.2754 0.7322 0.3385 0.7161 0.8820 0.6369 0.3652 0.5458 0.7328 0.9886 0.2394 0.6964 0.4858 0.6903 0.3385 0.7161 0.8820 0.6369 0.1774 0.4146 0.6908 0.7239 0.2394 0.6964 0.4858 0.6903 0.3385 0.7161 0.8820 0.6369 0.5397 0.1625 0.8757 0.0996 0.2394 0.6964 0.4858 0.6903 0.3385 0.7161 0.8820 0.6369 0.3652 0.5458 0.7328 0.9886 0.1400 0.8696 0.7921 0.3204 0.3385 0.7161 0.8820 0.6369

Más respuestas (1)

KSSV
KSSV el 10 de Ag. de 2021
Editada: KSSV el 10 de Ag. de 2021
y=cat(1,repmat(x1,size(x2,1),1),repelem(x2,size(x1,1),1));
Or
y=[repmat(x1,size(x2,1),1) ; repelem(x2,size(x1,1),1)];
  2 comentarios
Akash Pal
Akash Pal el 10 de Ag. de 2021
Thank you for giving the answer.But i did it already by myself .i asked if my matrix number is more than 2 or three.then what will be the procedure .
example a=3X4 ,b=4X4,c=5X4 then my output matrix should be y=60X12 ;
i want to form this type of matrix.
KSSV
KSSV el 10 de Ag. de 2021
Store the matrices into a cell and use cat.

Iniciar sesión para comentar.

Categorías

Más información sobre Cell Arrays en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by