How do I use regress function with 6 input variables?

8 views (last 30 days)
Hi,
I have 6 input variable in my function, following the example by matlab i did the next code:
y=A(1:38,:);
v=A(39:76,:);
d=A(77:114,:);
vi=A(115:152,:);
v2=v.^2;
v3=v.^3;
v4=v.^4;
X = [ones(size(v)) v2 v3 v4 d vi];
b = regress(y,X);
y is a matrix 38*25 and X 38*150
but, i have the next error:
Y must be a vector and must have the same number of rows as X.
I don't know how do column vectors... Anybody knows?
I see that rows of X have to be the number of elements of matrix y.
Thanks.

Accepted Answer

Walter Roberson
Walter Roberson on 6 Nov 2020
You cannot do that with regress(). regress() requires that y be a vector of target responses, one response for each row of x. Each row of x is a multi-dimensional point that has (conceptually) been put through a function that produces a scalar -- and y must be the result.
If your 38*25 y is conceptually the result of putting the input points through 25 different functions, then you need to loop over the columns of y.
  2 Comments
Marc Gironella
Marc Gironella on 6 Nov 2020
Hi Walter, thanks for your answer. I know that you mean.
You know how i can obtain the coeficients for my function?
My function is : y = a0+a1*v+a2*v^2+a3*v^3+a4*v^4+a5*d+a6*vi
Best regards.
Walter Roberson
Walter Roberson on 6 Nov 2020
Edited: Walter Roberson on 6 Nov 2020
a0_6 = [v(:).^0, v(:).^1, v(:).^2, v(:).^3, v(:).^4, d(:), vi(:)] \ y(:);

Sign in to comment.

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!