Filter löschen
Filter löschen

Combining elements from two arrays

3 Ansichten (letzte 30 Tage)
Laura
Laura am 19 Okt. 2022
Kommentiert: Laura am 20 Okt. 2022
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.

Akzeptierte Antwort

Torsten
Torsten am 19 Okt. 2022
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

Weitere Antworten (1)

AH
AH am 19 Okt. 2022
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

Kategorien

Mehr zu Matrices and Arrays finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by