필터 지우기
필터 지우기

Combining elements from two arrays

조회 수: 3 (최근 30일)
Laura
Laura 2022년 10월 19일
댓글: Laura 2022년 10월 20일
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