The if else statement does not read the other conditions
Show older comments
Hello. I have this code. I attached the matlab code and the excel file. This includes an excel file. The value for Wt1 in the cell F5 and F6 should be considered using the first two conditions in the if statement, yet it read the else statement instead
2 Comments
Walter Roberson
on 18 May 2021
Why are there ` ` around your assignment to b1 ?
Carmela Marie Lingad
on 18 May 2021
Accepted Answer
More Answers (1)
Steven Lord
on 18 May 2021
D1 = 3
Wl1 = 1.4
N1 = 15
%%interpolation for unit weight
if D1 < Wl1
Is 3 less than 1.4? No, so we do not execute the body of the if statement. We continue on to the elseif statement.
Wt1 = interp1(x1,a1,N1,'linear','extrap')
elseif D1 == Wl1
Is 3 exactly equal to 1.4? No, so we do not execute the body of the elseif statement. We continue on to the else statement.
Wt1 = interp1(x1,a1,N1,'linear','extrap')
else
We execute the body of the else statement.
Wt1 = interp1(x1,b1,N1,'linear','extrap')
end
MATLAB is behaving correctly based on what you showed us.
1 Comment
Carmela Marie Lingad
on 18 May 2021
Categories
Find more on Data Import from MATLAB 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!