Combining elements from two arrays

3 次查看(过去 30 天)
I have two arrays to start with:
B = 0.8147 0.6324 0.9575
0.9058 0.0975 0.9649
0.1270 0.2785 0.1576
0.9134 0.5469 0.9706
and
A = 0.9572 0.1419 0.7922
0.4854 0.4218 0.9595
0.8003 0.9157 0.6557
The array i want to end with is:
C = 0.4854 0.4218
0.9572 0.1419
0.1576 0.9649
So essentially i want the 2nd, 5th, 1st and 4th element of A and the 11th and 10th element of B.
I've managed to extract the elements from A that i need using the code >> C = A([2 5 ; 1 4]) but i cannot work out how to then add the 11th and 10th element of B.

采纳的回答

Torsten
Torsten 2022-10-19
A = [0.9572 0.1419 0.7922
0.4854 0.4218 0.9595
0.8003 0.9157 0.6557];
B = [0.8147 0.6324 0.9575
0.9058 0.0975 0.9649
0.1270 0.2785 0.1576
0.9134 0.5469 0.9706];
C = [A(2,1:2);A(1,1:2);B(3,3),B(2,3)]
C = 3×2
0.4854 0.4218 0.9572 0.1419 0.1576 0.9649

更多回答(1 个)

AH
AH 2022-10-19
You may want to try this
A = [0.9572, 0.1419, 0.7922;
0.4854, 0.4218, 0.9595;
0.8003, 0.9157, 0.6557];
B = [0.8147, 0.6324, 0.9575;
0.9058, 0.0975, 0.9649;
0.1270, 0.2785, 0.1576;
0.9134, 0.5469, 0.9706];
C = [A([2 5;1 4]);B([11 10])]
C = 3×2
0.4854 0.4218 0.9572 0.1419 0.1576 0.9649

类别

Help CenterFile Exchange 中查找有关 Matrices and Arrays 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by