I'm having trouble understanding how regress works in Matlab.
Say I have 2 arrays (X and Y), each having the same size (let's say they're each 1x10). From what I understand, the regress function should help me find the relationship between X and Y (I want to draw a best fit line through the plotted data), and then give me the slope. When I tried this in Matlab, I got an error saying that the 2 variables have a different number of rows....but they don't, do they?
I would just really appreciate it if anyone could help me understand how the function and its parameters work, just to get me going at a basic level.
Here's some code as an example:
x = [1,2,3,4,5,6,7,8,9,10];
y = [1,2,3,4,5,6,7,8,9,10]; %defining the arrays, they are linearly related
X=[x ones(size(x,1),1)]; %adding the (necessary?) column of ones
regress(y,X) % using the regress function for a relationship
I get this error:
??? Error using ==> regress at 64
The number of rows in Y must equal the number of rows in X.