Azzera filtri
Azzera filtri

how to solve this problem?

1 visualizzazione (ultimi 30 giorni)
Arpita
Arpita il 12 Gen 2024
Risposto: Voss il 13 Gen 2024
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?

Risposte (2)

Walter Roberson
Walter Roberson il 12 Gen 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.

Voss
Voss il 13 Gen 2024
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

Categorie

Scopri di più su Data Types in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by