if elseif statement operands
8 views (last 30 days)
I have a problem with statement if else, it doesn't work. Error:
Operands to the and && operators must be convertible to logical scalar values.
Error in My_Project (line 31) elseif ((f0<=f)&&(f<fl));
f = [31.5 40 50 63 80 100 125 160 200 250 315 400 500 630 800....
1000 1250 1600 2000 2500 3150 4000 5000 6300 8000];
nl2605 on 1 Apr 2014
You have to give a condition for elseif. Something like
elseif ((f0<=f) && (f<f1)== 1) or zero according to your condition.
Jos (10584) on 1 Apr 2014
f is an array with multiple elements, and f0 is a scalar (single element). The statement " f < f0 " returns an array the same size as f with true and false values for each element of f. You can use the functions ALL or ANY to convert this to a single value, so it can be used in an IF condition.
However, I suspect that you want to create a new array TL that has the same number of elements as f, but some elements of TL are calculated one way and some another way ...
You can try this
% Assuming TLm, TLm1, TLm2, and d are scalars!
TL = repmat(TLm1+TLm2+6, size(f)) % default values
q1 = (f0<=f) & (f<fl) % condition 1
TL(q1) = TLm1 + TLm2 + 20.*log10(f(q1).*d)-29
q2 = f < f0 % condition 2
TL(q2) = TLm