Filter löschen
Filter löschen

Given matrices XX and YY of sizes 3X3, how can I generate the following matrix: [XX(1,1) YY(1,1); XX(1,2) YY(1,2)... ?

1 Ansicht (letzte 30 Tage)
Given matrices XX and YY of sizes 3X3, how can I generate the following matrix:
[XX(1,1) YY(1,1); XX(1,2) YY(1,2);XX(1,3) YY(1,3); XX(2,1) YY(2,1); XX(2,2) YY(2,2); XX(2,3) YY(2,3); XX(3,1) YY(3,1); XX(3,2) YY(3,2); XX(3,3) YY(3,3)]
I mean of course, without writing it explicitly and without loops.
Thanks!!

Akzeptierte Antwort

C.J. Harris
C.J. Harris am 15 Nov. 2012
or:
XX = magic(3);
YY = eye(3);
XX_trans = transpose(XX);
YY_trans = transpose(YY);
out = [XX_trans(:) YY_trans(:)];

Weitere Antworten (2)

Matt Fig
Matt Fig am 15 Nov. 2012
Bearbeitet: Matt Fig am 15 Nov. 2012
For example:
XX = magic(3);
YY = cumsum(ones(3));
% Your requested matrix.
ZZ = [reshape(XX.',[],1) reshape(YY.',[],1)]

C.J. Harris
C.J. Harris am 15 Nov. 2012
Bearbeitet: C.J. Harris am 15 Nov. 2012
This is one way of doing it - expanding on my answer to your previous question:
XX = magic(3);
YY = eye(3);
out = unique(nchoosek([1:3, 1:3], 2), 'rows');
XX_Array = arrayfun(@(x)[(XX(out(x,1),out(x,2)))], 1:size(out,1))';
YY_Array = arrayfun(@(x)[(YY(out(x,1),out(x,2)))], 1:size(out,1))';
combArray = [XX_Array YY_Array];

Kategorien

Mehr zu Loops and Conditional Statements 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