how to solve this problem?
1 view (last 30 days)
Show older comments
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 Comments
Answers (2)
Walter Roberson
on 12 Jan 2024
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 Comments
Voss
on 13 Jan 2024
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 Comments
See Also
Categories
Find more on Data Types in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!