displaying 2 graphs in singe run

1 次查看(过去 30 天)
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

采纳的回答

Star Strider
Star Strider 2021-5-28
‘... 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 个评论
Muhammad
Muhammad 2021-5-28
yes it works and how to name the both plots
Star Strider
Star Strider 2021-5-28
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))
.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Directed Graphs 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by