How do I plot from multiple mfile into a same figure

2 ビュー (過去 30 日間)
Chung Zhen Choo
Chung Zhen Choo 2019 年 5 月 11 日
回答済み: G A 2019 年 5 月 11 日
figure(2); %figure 2
x = 0:2:30;
% L0-L200 are some value
subplot(2,3,1),plot(x,L0,'ro'),axis([0 30 -8 0])
subplot(2,3,2),plot(x,L40,'ro'),axis([0 30 -8 0])
subplot(2,3,3),plot(x,L80,'ro'),axis([0 30 -8 0])
subplot(2,3,4),plot(x,L120,'ro'),axis([0 30 -8 0])
subplot(2,3,5),plot(x,L160,'ro'),axis([0 30 -8 0])
subplot(2,3,6),plot(x,L200,'ro'),axis([0 30 -8 0])
hold all
%% This is mfile 1
figure(2); %figure 2
p0 = polyfit(x,L0,6);
xfit = linspace(0,30,900);
yfit = polyval(p0,xfit);
subplot(2,3,1)
plot(xfit,yfit)
hold off
%% This is mfile 2
Hi everyone, It wont work with this code. It will just overwrite all the previous subplot and create a new one in mfile 2
Thanks in advance

回答 (1 件)

G A
G A 2019 年 5 月 11 日
Add "hold on" In your mfile2 anywhere before "plot(xfit,yfit)" :
figure(2); %figure 2
hold on

カテゴリ

Help Center および File ExchangeSubplots についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by