Effacer les filtres
Effacer les filtres

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 vue (au cours des 30 derniers jours)
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!!

Réponse acceptée

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

Plus de réponses (2)

Matt Fig
Matt Fig le 15 Nov 2012
Modifié(e) : Matt Fig le 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 le 15 Nov 2012
Modifié(e) : C.J. Harris le 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];

Catégories

En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by