数学建模社区-数学中国

标题: 急求帮助…… [打印本页]

作者: 苏简若的爱    时间: 2012-8-2 11:10
标题: 急求帮助……
x=(1:10)';
y=10-2*x+randn(10,1);
y(10)=0;
bls=regress(y,[ones(10,1) x]) %线性拟合
brob=robustfit(x,y) %稳健拟合
scatter(x,y)
hold on
plot(x,bls(1)+bls(2)*x,’:’)
plot(x,brob(1)+brob(2)*x,’r')

运行结果是:
plot(x,bls(1)+bls(2)*x,’:’)
                           |
Error: Missing variable or function.

还有单独运行时出现的是:
Index exceeds matrix dimensions.(指数大于矩阵的维数)
作者: zhangquan    时间: 2012-8-2 11:38
不了解啊
作者: liwenhui    时间: 2012-8-2 18:34
x=[1:10]';
y=10-2*x+randn(10,1);
y(10)=0;
bls=regress(y,[ones(10,1) x]) %线性拟合
brob=robustfit(x,y) %稳健拟合
scatter(x,y)
hold on
plot(x,bls(1)+bls(2)*x,':')
plot(x,brob(1)+brob(2)*x,'r')

第一行,定义自变量时用[],不要用()

得到结果:

bls =

    8.4470
   -1.4334


brob =

    9.6654
   -1.8431


输出图像:

we.jpg
作者: 苏简若的爱    时间: 2012-8-2 21:29
liwenhui 发表于 2012-8-2 18:34
x=[1:10]';
y=10-2*x+randn(10,1);
y(10)=0;

好的,谢谢。我是一个初学matlab的学生,以后希望多多指教!




欢迎光临 数学建模社区-数学中国 (http://www.madio.net/) Powered by Discuz! X2.5