If statement with multiple variables, or if the variables can be shortened.
48 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Dominic Garcia
il 18 Ott 2020
Modificato: Adam Danz
il 18 Ott 2020
x is a decimal number always smaller than one based on the users input.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/383948/image.png)
So I want the program to check if the value of a,b,c or d is less than a certain value or greater than, and produce an output.
0 Commenti
Risposta accettata
Adam Danz
il 18 Ott 2020
Modificato: Adam Danz
il 18 Ott 2020
if 0.6<=a && 0.6<=b && 0.6<=c && 0.6<=d && a<.10 && b<.10 && c<.10 && d<.10
dime = 1;
end
or
if all(0.6 < [a,b,c,d]) && all([a,b,c,d]<0.10)
dime = 1
end
Most important, this will never return a true value
all(0.6 < [a,b,c,d]) && all([a,b,c,d]<0.10)
If .6 is less than x, x will always be greater than 0.10.
You can brush up on Matlab indexing here
0 Commenti
Più risposte (1)
Asad (Mehrzad) Khoddam
il 18 Ott 2020
if x<1 && x<=0.75
a = x - 0.75;
elseif x>=0.5
b = x - 0.5;
elseif x>=2.5
c = x - 0.25;
else
d = x;
end
% make an array of values
v = [a, b, c , d];
if all(v>0.1) && all(v<=0.6)
dime = 1;
end
0 Commenti
Vedere anche
Categorie
Scopri di più su Logical 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!