string inputs and if else statement

2 次查看(过去 30 天)
function untitled(country1,state1,country2,state2,names,days,avg_days,dailycases)
if state1= isempty and state2 = isempyty
Index1 = strcmpi(names,country1);
dailydata1= dailycases(Index1,:);
daily_cases1 = movmean(dailydata1, avg_days);
daily__cases1=daily_cases1(1,:)
figure
subplot(2,1,1)
title('country1')
bar(days(1:end-1),daily__cases1);
Index2 = strcmpi(names,country2);
dailydata2= dailycases(Index2,:);
daily_cases2 = movmean(dailydata2, avg_days);
daily__cases2=daily_cases2(1,:)
subplot(2,1,2)
title('country2')
bar(days(1:end-1),daily__cases2);
else
Index1 = strcmpi(names,state1);
dailydata1= dailycases(Index1,:);
daily_cases1 = movmean(dailydata1, avg_days);
daily__cases1=daily_cases1(1,:)
figure
subplot(2,1,1)
title('country1')
bar(days(1:end-1),daily__cases1);
Index2 = strcmpi(names,state2);
dailydata2= dailycases(Index2,:);
daily_cases2 = movmean(dailydata2, avg_days);
daily__cases2=daily_cases2(1,:)
subplot(2,1,2)
title('country2')
bar(days(1:end-1),daily__cases2);
end
how i should write code after if statement so that if state =empty
the it execute the if part and else it execute else part
note that country1, country2,state1,state2 they all are string input

采纳的回答

Star Strider
Star Strider 2021-5-28
... how i should write code after if statement so that if state =empty ...
This line:
if state1= isempty and state2 = isempyty
becomes:
if isempty(state1) && isempty(state2)
If that is not true (both are not empty), the else section should execute.
.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Characters and Strings 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by