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 Center および File ExchangeDirected Graphs についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by