The if else statement does not read the other conditions

4 ビュー (過去 30 日間)
Carmela Marie Lingad
Carmela Marie Lingad 2021 年 5 月 18 日
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 件のコメント
Walter Roberson
Walter Roberson 2021 年 5 月 18 日
Why are there ` ` around your assignment to b1 ?
Carmela Marie Lingad
Carmela Marie Lingad 2021 年 5 月 18 日
Sorry, It's just a typo error. But in may matlab code, there is no ` `

サインインしてコメントする。

採用された回答

Walter Roberson
Walter Roberson 2021 年 5 月 18 日
"based on the assigned value of D1 and Wl1, it should be applied in the first condition of the if statement"
Huh? D1 is 3 and Wl1 is 1.4, and 3 < 1.4 is false, so the last statement is the correct one to use.
  6 件のコメント
Walter Roberson
Walter Roberson 2021 年 5 月 18 日
Change
[strings] = xlsread('Terzaghi.xlsx','Sheet1','E5:E34'); %%Soil classification
to
[~,strings] = xlsread('Terzaghi.xlsx','Sheet1','E5:E34'); %%Soil classification
Change
if isequal(S1,'GS')
coh1 = 0
elseif isequal(S1,'S')
coh1 = 0
elseif isequal(S1,'G')
coh1 = 0
else
coh1 = 0.06 .* 101.325 .* N1
end
to
mask = ismember(S1, {'GS', 'S', 'G'});
coh1(mask) = 0;
coh1(~masK) = 0.06 .* 101.325 .* N1(~mask);
Carmela Marie Lingad
Carmela Marie Lingad 2021 年 5 月 18 日
Wow. Thank you so much. This really helped a lot.

サインインしてコメントする。

その他の回答 (1 件)

Steven Lord
Steven Lord 2021 年 5 月 18 日
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 件のコメント
Carmela Marie Lingad
Carmela Marie Lingad 2021 年 5 月 18 日
Sorry. I edited the question. I also attached the matlab code with the corresponding excel file.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeData Import from MATLAB についてさらに検索

製品


リリース

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by