if elseif statement operands
Show older comments
Hi,
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));
%%My_Project
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];
f0=220;
fl=2.58;
if (f<f0)
TL=TLm;
elseif ((f0<=f)&&(f<fl));
TL=TLm1+TLm2+20.*log10(f.*d)-29;
else
TL=TLm1+TLm2+6;
end
Thank you,
Dominika
Answers (2)
nl2605
on 1 Apr 2014
0 votes
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
Categories
Find more on Transaction Level Model Generation 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!