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)... ?
3 次查看(过去 30 天)
显示 更早的评论
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!!
0 个评论
采纳的回答
C.J. Harris
2012-11-15
or:
XX = magic(3);
YY = eye(3);
XX_trans = transpose(XX);
YY_trans = transpose(YY);
out = [XX_trans(:) YY_trans(:)];
更多回答(2 个)
C.J. Harris
2012-11-15
编辑:C.J. Harris
2012-11-15
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];
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Matrices and Arrays 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!