求助:为什么我输入下​面的数据拟合代码只出​现了一个图。

x=[0 0.01 0.02 0.03 0.04 0.06 0.08 0.10 0.14 0.18];
y=[48 30 20 13 9 5 3 1 1 0];
figure('position',[50 50 1500 400]);
for i=1;3
subplot(1,3,i);
p=polyfit(x,y,i);
xfit=[x(1);0.1;x(end)];
yfit=polyval(p,xfit);
plot(x,y,'ro',xfit,yfit);
set(gca,'fontsize',14);
ylim([0,50]);
legend(4,'data points','fitted curve');
end

 采纳的回答

0 个投票

你想要的是这个吗,如果是的话,你的程序有两个问题:
1、legend函数第一个参数那里应该是个向量,也就是一维矩阵
2、你的for循环的1和3之间应该是冒号而不是分号,小细节要注意哈

更多回答(0 个)

类别

帮助中心File Exchange 中查找有关 Legend 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!