The if else statement does not read a string in the excel file

1 次查看(过去 30 天)
I have a question. I have attached a matlab code and an excel file.
My problem is on the parameter coh1. The condition should be, if the soil classification has the texts "GS", "S", or "G", the value of coh1 should be 0. Otherwise, the value of coh1 should be the product of 0.06 .* 101.325 .* N1. But when I use the if statement, it only reflects the value of the else statement in which, the value of coh1 for cell K5:K7 should be 0. I don't know what did I miss.

采纳的回答

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);

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Agriculture 的更多信息

标签

产品


版本

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by