Using two logical vectors to extract data

조회 수: 2 (최근 30일)
Matlab_G
Matlab_G 2022년 11월 21일
답변: Walter Roberson 2022년 11월 21일
Hello,
I would like to find the average of row 3 elements only when row 1==2000 AND row 2==1. (The answer should be 4 in the example below)
example:
A=
2000 2000 2000 2001 2001
1 1 2 1 1
5 3 8 9 7
Is there a way of using logical vectors twice?
row1=A(1,:)==2000 && row2=A(2,:)==1 , then finding the average of the third row or would an if statement be better suited?
Thanks in advance

답변 (1개)

Walter Roberson
Walter Roberson 2022년 11월 21일
mean(A(3, A(1,:) == 2000 & A(2,:) == 1))

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by