필터 지우기
필터 지우기

how to solve this problem?

조회 수: 1 (최근 30일)
Arpita
Arpita 2024년 1월 12일
답변: Voss 2024년 1월 13일
Q_p = [Q1 Q2 Q3 Q4 Q5]
Q = mean(Q_p)
if (Q < 50) & (Q > 250);
q_1 = 0;
if (Q_p >= 50) & (Q_p < 250);
q_1 = [Q_p];
Q = mean(q_1)
end
end
Q1 = 1.05012447435464
Q2 = 25.3238658780576
Q3 = 26.3238658780576
Q4 = 55.0712183513003
Q5 = 6.7116155293271
q_1 =
1×5 logical array
0 0 0 1 0
Q = 0.2 0.2
I want to get the value of Q4 in numerical form, but it is showing me logical array. What am I doing wrong?

답변 (2개)

Walter Roberson
Walter Roberson 2024년 1월 12일
Q_p = [Q1 Q2 Q3 Q4 Q5]
That is a vector.
if (Q_p >= 50) & (Q_p < 250);
You are testing the vector to see if it is >= 50 and < 250. The test will be considered true only if all of the individual tests come out true.
Note that you do not assign to q_1 if (Q < 50) & (Q > 250) is false.

Voss
Voss 2024년 1월 13일
Q_p = [1.05012447435464, 25.3238658780576, 26.3238658780576, 55.0712183513003, 6.7116155293271]
Q_p = 1×5
1.0501 25.3239 26.3239 55.0712 6.7116
idx = (Q_p >= 50) & (Q_p < 250); % logical index
Q_p(idx)
ans = 55.0712

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by