苏简若的爱 发表于 2012-8-2 11:10

急求帮助……

x=(1:10)';
y=10-2*x+randn(10,1);
y(10)=0;
bls=regress(y,) %线性拟合
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=';
y=10-2*x+randn(10,1);
y(10)=0;
bls=regress(y,) %线性拟合
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


输出图像:

苏简若的爱 发表于 2012-8-2 21:29

liwenhui 发表于 2012-8-2 18:34 static/image/common/back.gif
x=';
y=10-2*x+randn(10,1);
y(10)=0;


好的,谢谢。我是一个初学matlab的学生,以后希望多多指教!
页: [1]
查看完整版本: 急求帮助……