how to solve this problem?
1 次查看(过去 30 天)
显示 更早的评论
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?
0 个评论
回答(2 个)
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.
0 个评论
Voss
2024-1-13
Q_p = [1.05012447435464, 25.3238658780576, 26.3238658780576, 55.0712183513003, 6.7116155293271]
idx = (Q_p >= 50) & (Q_p < 250); % logical index
Q_p(idx)
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!