string inputs and if else statement
4 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Muhammad
el 28 de Mayo de 2021
Respondida: Star Strider
el 28 de Mayo de 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
0 comentarios
Respuesta aceptada
Star Strider
el 28 de Mayo de 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.
.
0 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Characters and Strings en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!