How to plot multiple graphs in one figure ?
古いコメントを表示
I have two codes. Each code has four graphs. I want to plot two graphs in one figure. For example: Dead nodes vs Round graph of two should be in one figure. In the same way other graphs also. I tried hold on function but still not getting. How to merge the two codes in order to get the graphs ?
3 件のコメント
Amit Bhowmick
2021 年 6 月 29 日
Hi sree,
The question is not clear. you can check with following modifications:
Mod: 1
figure (1);
hold
plot(r,STATISTICS.DEAD);
xlabel('Rounds');
ylabel('Dead Nodes');
title('MODLEACH');
%figure (2);
plot(r,STATISTICS.PACKETS_TO_BS);
xlabel('Rounds');
ylabel('Packets to BS');
title('MODLEACH');
%figure (4);
plot(r,STATISTICS.PACKETS_TO_CH);
xlabel('Rounds');
ylabel('Packets to CH')
title('MODLEACH');
%figure (5);
plot(r,STATISTICS.ALLIVE);
xlabel('Rounds');
ylabel('Allive nodes')
title('MODLEACH');
Mod: 2
If you are not getting two curve in a single figure using hold command then try to use it,
if(ishold==0)
hold on;
end
Amanda Liu
2021 年 6 月 29 日
編集済み: Amanda Liu
2021 年 6 月 29 日

figure(1)
subplot(2,1,1) % 2 rows, 1 column, first position
plot(r,STATISTICS.DEAD);
title('Dead Nodes vs Rounds')
xlabel 'Rounds';
ylabel 'Dead Nodes';
subplot(2,1,2) % 2 rows, 1 column, second position
plot(r,STATISTICS.ALLIVE);
title('Live Nodes vs Rounds')
xlabel 'Rounds';
ylabel 'Live Nodes';
figure(2)
subplot(2,1,1)
plot(r,STATISTICS.PACKETS_TO_BS);
title('Pkts to BS per round')
xlabel 'Rounds';
ylabel 'Pkts to BS ';
subplot(2,1,2)
plot(r,STATISTICS.PACKETS_TO_CH);
title('Pkts to CH per round')
xlabel 'Rounds';
ylabel 'Pkts to CH ';
Nghia Tran
2023 年 2 月 2 日
thank u
採用された回答
その他の回答 (1 件)
Devanuj Deka
2021 年 7 月 12 日
It is my understanding that you want to plot two graphs in one figure. You tried hold on but it didn't work.
It is not clear whether you want both plots in the same graph, or both plots in separate graphs but in the same window. Below are the possible solutions for either of those which you can try. I've taken dead nodes v/s rounds and alive nodes v/s rounds for the plots.
1) hold on, hold off – both dead and alive nodes in the same plot, same figure
figure(1)
plot(r,STATISTICS.DEAD);
hold on;
title('Nodes vs Rounds')
plot(r,STATISTICS.ALLIVE);
xlabel 'Rounds';
ylabel 'Nodes';
hold off;
legend('Dead Nodes','Live Nodes','Location','best');
Documentation: hold
2) subplot – dead nodes and alive nodes in two separate plots, but in the same figure
figure(1)
subplot(2,1,1)
plot(r,STATISTICS.DEAD);
title('Dead Nodes vs Rounds')
xlabel 'Rounds';
ylabel 'Dead Nodes';
subplot(2,1,2)
plot(r,STATISTICS.ALLIVE);
title('Live Nodes vs Rounds')
xlabel 'Rounds';
ylabel 'Live Nodes';
Documentation: subplot
1 件のコメント
Jonas/Ren
2025 年 1 月 16 日
Can this be done for three separate plots?
カテゴリ
ヘルプ センター および File Exchange で 2-D and 3-D Plots についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
