作业帮 > 综合 > 作业

matlab拟合直线.

来源:学生作业帮 编辑:作业帮 分类:综合作业 时间:2024/05/15 00:44:45
matlab拟合直线.
x=[-0.932 0.981 0.019 -0.613 -0.256 -0.751 0.312];
y=[9.154 -9.625 -0.186 6.281 2.203 7.456 3.104];
做出有四个象限的那种图.我做的只有一个象限.
用axis([xmin xmax ymin ymax]分别设置x和y轴的最大最小值
再问: 具体格式什么样的? 我弄了 x=[-0.932 0.981 0.019 -0.613 -0.256 -0.751 0.312]; y=[9.154 -9.625 -0.186 6.281 2.203 7.456 3.104]; p=polyfit(x,y,1); Y=polyval(p,x); plot(x,y,'*',x,Y) axis([-1.1 1.1 -10 10]) grid on 这样不行啊。
再答: function PlotAxisAtOrigin(x,y); % PlotAxisAtOrigin Plot axes through the origin % Written by DOTA figure; % PLOT if nargin == 2 plot(x,y); end; hold on; % GET TICKS X=get(gca,'Xtick'); Y=get(gca,'Ytick'); % GET LABELS XL=get(gca,'XtickLabel'); YL=get(gca,'YtickLabel'); % GET OFFSETS Xoff=diff(get(gca,'XLim'))./30; Yoff=diff(get(gca,'YLim'))./30; % DRAW AXIS LINEs plot(get(gca,'XLim'),[0 0],'k'); plot([0 0],get(gca,'YLim'),'k'); % DRAW TICKS XTickLength = (X(2) - X(1))/10; YTickLength = (Y(2) - Y(1))/10/XTickLength; for i=1:length(X) plot([X(i) X(i)],[0 YTickLength],'-k'); end; for i=1:length(Y) plot([XTickLength 0],[Y(i) Y(i)],'-k'); end; % ADD LABELS text(X,zeros(size(X))-2.*Yoff,XL); text(zeros(size(Y))-2.*Xoff,Y,YL); box off; axis off; set(gcf,'color','w'); 先在m文件中保存以上程序。 然后在命令窗口输入: x=[-0.932 0.981 0.019 -0.613 -0.256 -0.751 0.312]; y=[9.154 -9.625 -0.186 6.281 2.203 7.456 3.104]; p=polyfit(x,y,1); Y=polyval(p,x); PlotAxisAtOrigin(x,Y); 希望能帮到你
再问: 不懂啊。。。