least square method.getting error using '\' or linsolve. pls help

any kind folks who can help me out. i'm trying to implement least square method, but i'm getting some error using linsolve and '\' function. please help, and million thanks in advance!
for a =1:400
for P=1:49
o=(P-1)*243;
for r=1:35
if r==35
t=-2;
pA1(1:5,1,r,P)=A(7*r-6+o:7*r+t+o,a);
pB1(1:5,1,r,P)=B(7*r-6+o:7*r+t+o,a);
beta(r,P)=linsolve(pA1,pB1); <--- error
% beta(r,P)=pA1\pB1;
else
t=0;
pA(1:7+t,1,r,P)=A(7*r-6+o:7*r+t+o,a);
pB(1:7+t,1,r,P)=B(7*r-6+o:7*r+t+o,a);
beta(r,P)=linsolve(pA,pB);; <---- error
% beta(r,P)=pA\pB;
end
end
end

댓글 수: 2

Can you please tell us what the complete error message is. We cannot read minds, and we also cannot read what is on your computer screen.
many thanks for willing to help me out.
The complete message for linsolve is as follows:
Error using linsolve
First and second arguments must be 2D.
Error in modifiedregression (line 34)
beta(r,P)=linsolve(pA,pB);
whereas for \ is as follows:
Error using \
Inputs must be 2-D, or at least one input must be scalar.
To compute elementwise LDIVIDE, use LDIVIDE (.\) instead.
Error in modifiedregression (line 36)
beta(r,P)=pA\pB;

댓글을 달려면 로그인하십시오.

답변 (1개)

Matt J
Matt J 2015년 1월 23일
편집: Matt J 2015년 1월 23일

0 개 추천

Your pA1 and pB1 are 4D arrays. However linsolve(A,B) expects A and B to be 2D matrices, and similarly for '\'.

댓글 수: 4

seprienna
seprienna 2015년 1월 23일
편집: seprienna 2015년 1월 23일
can you recommend a solution for least square method please? Manyt hanks in advance
Matt J
Matt J 2015년 1월 23일
편집: Matt J 2015년 1월 23일
No, the intention of your code is not obvious. Don't you know what equations you want linsolve to solve? If it's now clear from my Answer that the data you're giving it is wrong, doesn't that tip you off as to what it should really be?
i'm still trying to figure out a method to overcome the arrays to matrices. any tips from you? your kind reply is greatly appreciated
Nope, no tips. We have no way of understanding what your code is trying to do unless you explain it to us.

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Calendar에 대해 자세히 알아보기

제품

질문:

2015년 1월 23일

댓글:

2015년 1월 23일

Community Treasure Hunt

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

Start Hunting!

Translated by