string inputs and if else statement

4 Ansichten (letzte 30 Tage)
Muhammad
Muhammad am 28 Mai 2021
Beantwortet: Star Strider am 28 Mai 2021
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

Akzeptierte Antwort

Star Strider
Star Strider am 28 Mai 2021
... 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.
.

Weitere Antworten (0)

Kategorien

Mehr zu Matrices and Arrays finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by