string inputs and if else statement

4 visualizzazioni (ultimi 30 giorni)
Muhammad
Muhammad il 28 Mag 2021
Risposto: Star Strider il 28 Mag 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

Risposta accettata

Star Strider
Star Strider il 28 Mag 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.
.

Più risposte (0)

Categorie

Scopri di più su Matrices and Arrays in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by