Filter löschen
Filter löschen

merging the matrices

5 Ansichten (letzte 30 Tage)
kash
kash am 20 Mär. 2012
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

Akzeptierte Antwort

Daniel Shub
Daniel Shub am 20 Mär. 2012
reshape([A B]', 3, 6)'
ans =
1 5 10
25 1 2
10 20 30
2 5 9
2 5 6
1 0 5

Weitere Antworten (2)

Thomas
Thomas am 20 Mär. 2012
try
c=[];
for i=1:size(a)
d(:,:)=[a(i,:);b(i,:)];
c=[c;d];
end
c
  5 Kommentare
Thomas
Thomas am 20 Mär. 2012
I think you need to use..
for i=1:length(a), instead of size(a)
kash
kash am 21 Mär. 2012
Thanks thomas

Melden Sie sich an, um zu kommentieren.


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

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Data Types finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by