2

Given :

Y=[81  55 80  24 78 52  88 45 50 69 66 45 24 43 38 72  41  48 52  52  66 89];

X=[124 49 181 4  22 152 75 54 43 41 17 22 16 10 63 170 125 15 222 171 97 254];

I want to regress Y on X (simple linear regression). I tried with this code :

b= regress(Y,X)

But it gives me this error :

??? Error using ==> regress at 65 
The number of rows in Y must equal the number of rows in X.

Thanks for any help.

Dan
  • 45,079
  • 17
  • 88
  • 157
blackbishop
  • 30,945
  • 11
  • 55
  • 76
  • What version of Matlab are you using? If you're up to date then you should probably consider using `fitlm` instead of `regress`... – Dan Jan 15 '15 at 08:52
  • I'm using Matlab 7.10.0 – blackbishop Jan 15 '15 at 08:55
  • 1
    That's 2010a if I'm not mistaken? So in that case it's much to old for `fitlm`. You should check if your license allows you to get the latest version though - there have been a lot of really worthwhile improvements since then – Dan Jan 15 '15 at 08:57

1 Answers1

1

regress expect its inputs as column vectors.
Transposing (.') your inputs should do the trick:

>> b = regress( Y.', X.' )
b =
0.4291
Shai
  • 111,146
  • 38
  • 238
  • 371
  • 1
    I think you should reword this, `X` should not be a column vector but an *n*-by-*p* matrix where *p* is the number of inputs or explanatory or independent variables (in this case 1). Also worth adding a warning here the `regress` will not include an offset term unless you explicitly augment your `X` matrix with a column of `ones` – Dan Jan 15 '15 at 08:54