Azzera filtri
Azzera filtri

Combining elements from two arrays

3 visualizzazioni (ultimi 30 giorni)
Laura
Laura il 19 Ott 2022
Commentato: Laura il 20 Ott 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.

Risposta accettata

Torsten
Torsten il 19 Ott 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

Più risposte (1)

AH
AH il 19 Ott 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

Categorie

Scopri di più su Matrices and Arrays in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by