displaying 2 graphs in singe run

1 visualización (últimos 30 días)
Muhammad
Muhammad el 28 de Mayo de 2021
Comentada: Star Strider el 28 de Mayo de 2021
function compare_cases(country1,country2,names,days,avg_days,dailycases)
Index1 = strcmpi(names,country1);
% [row,col] = find(not(doublefun('isempty',IndexC)))
dailydata1= dailycases(Index1,:);
daily_cases1 = movmean(dailydata1, avg_days);
figure;
title('country1')
bar(days(1:end-1),daily_cases1);
% bar(days(1:end-1),dailydata);
Index2 = strcmpi(names,country2);
% [row,col] = find(not(doublefun('isempty',IndexC)))
dailydata2= dailycases(Index1,:);
daily_cases2 = movmean(dailydata2, avg_days);
figure
title('country2')
bar(days(1:end-1),daily_cases2);
end
i want to compare the data of country1 and country2 using bar graph
but evry time it replace the first graph so what should be done so that i get two graphs

Respuesta aceptada

Star Strider
Star Strider el 28 de Mayo de 2021
‘... but evry time it replace the first graph ...’
It does not replace them. It creates a second figure and that figure is on top of the first figure. It is necessary to select the individual figures to see both of them.
Perhaps creating them as subplots instead would do what you want —
function compare_cases(country1,country2,names,days,avg_days,dailycases)
Index1 = strcmpi(names,country1);
% [row,col] = find(not(doublefun('isempty',IndexC)))
dailydata1= dailycases(Index1,:);
daily_cases1 = movmean(dailydata1, avg_days);
figure
subplot(2,1,1)
title('country1')
bar(days(1:end-1),daily_cases1);
% bar(days(1:end-1),dailydata);
Index2 = strcmpi(names,country2);
% [row,col] = find(not(doublefun('isempty',IndexC)))
dailydata2= dailycases(Index1,:);
daily_cases2 = movmean(dailydata2, avg_days);
subplot(2,1,2)
title('country2')
bar(days(1:end-1),daily_cases2);
end
.
  2 comentarios
Muhammad
Muhammad el 28 de Mayo de 2021
yes it works and how to name the both plots
Star Strider
Star Strider el 28 de Mayo de 2021
They are named as 'country1' and 'country2'.
Apparently ‘names’ are the country names, and I assume they are in a cell array. If so, the title calls change to:
title(names{1})
for ‘country1’, and
title(names{2})
for ‘country2’, respectively.
If they are string arrays instead, that would be:
title(names(1))
and
title(names(2))
.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Directed Graphs 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!

Translated by