displaying 2 graphs in singe run

조회 수: 1 (최근 30일)
Muhammad
Muhammad 2021년 5월 28일
댓글: Star Strider 2021년 5월 28일
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