displaying 2 graphs in singe run
1 view (last 30 days)
Show older comments
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
0 Comments
Accepted Answer
Star Strider
on 28 May 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 Comments
Star Strider
on 28 May 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))
.
More Answers (0)
See Also
Categories
Find more on 2-D and 3-D Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!