merging the matrices

i have two matrices
A=[1 5 10
10 20 30
2 5 6]
B=[ 25 1 2
2 5 9
1 0 5]
i want to merge these two matrices such that i need output as
C=[1 5 10
25 1 2
10 20 30
2 5 9
2 5 6
1 0 5]
please help

 Respuesta aceptada

Daniel Shub
Daniel Shub el 20 de Mzo. de 2012

0 votos

reshape([A B]', 3, 6)'
ans =
1 5 10
25 1 2
10 20 30
2 5 9
2 5 6
1 0 5

Más respuestas (2)

Thomas
Thomas el 20 de Mzo. de 2012

0 votos

try
c=[];
for i=1:size(a)
d(:,:)=[a(i,:);b(i,:)];
c=[c;d];
end
c

5 comentarios

kash
kash el 20 de Mzo. de 2012
Thomas this works for 3x3 matrix,but for 25x64 matrix,i get error,please help
Daniel Shub
Daniel Shub el 20 de Mzo. de 2012
What error do you get. Does it fail for a 4x3 matrix? Can you post a minimal example of the failure?
Thomas
Thomas el 20 de Mzo. de 2012
I tried this on two 25x64 matrices and it still works.. What error are you getting..
Thomas
Thomas el 20 de Mzo. de 2012
I think you need to use..
for i=1:length(a), instead of size(a)
kash
kash el 21 de Mzo. de 2012
Thanks thomas

Iniciar sesión para comentar.

Jonathan Sullivan
Jonathan Sullivan el 20 de Mzo. de 2012

0 votos

C = [A B];
C = reshape(C',[],3)'

2 comentarios

kash
kash el 20 de Mzo. de 2012
in ur code am not getting exact result
Jonathan Sullivan
Jonathan Sullivan el 20 de Mzo. de 2012
I'm sorry. I mixed up the [] and the 3. It should read:
C = [A B];
C = reshape(C',3,[])'

Iniciar sesión para comentar.

Etiquetas

Preguntada:

el 20 de Mzo. de 2012

Community Treasure Hunt

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

Start Hunting!

Translated by