least-square problem and calling of that function
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Erik
am 10 Apr. 2014
Beantwortet: Star Strider
am 10 Apr. 2014
Hello!
I seem to have a problem with least-square method. I would estimate that the error is simple but I must admit I am code blind at this moment. The file is displayed below and the error directly after. I have marked the rows in the .m-file which is displayed in the error message with >>>.
function[A Deltapar] = MKA(x,y,deltay,n) A = []; Deltapar = []; X=[];
%-----------------------------------------------------------------------------------------------% checking if the input for the matrix size is correct >>>if(size(x)(2)~=1) x=x'; end if(size(y)(2)~=1) y=y'; end if(size(deltay)(2)~=1) deltay=deltay'; end %----------------------------------------------------------------------------------------------- % checking if the matrix x,y, and deltay has the correct size and after that, execute least square method.
if(size(x)(2)==1 && size(y)(2) ==1 && size(deltay)(2)==1)
%----------------------------------------------------------------------------------------------- % Conducting weighted least squares fit on the matrices x and y have the same format. % If not, a message is returned back an x and y are not of the same length. if(length(x)==length(y)) for i=0:n X=[X x.^i]; end sigma=deltay; vminus1 = diag(1./sigma.^2); A = inv(X' * vminus1 * X) * (X' * vminus1 * y); DeltaA = inv(X' * vminus1 * X); Deltapar = sqrt(diag(DeltaA)); else disp('x,y does not have the same length'); end %----------------------------------------------------------------------------------------------- % prints out "you have not written the input on correct form"
else disp('you have not written the input on correct form'); end
??? Error: File: MKA.m Line: 17 Column: 4 ()-indexing must appear last in an index expression.
except this problem I seem to have difficulties with calling this file from another .m-file having code shown in the error message.
the error message is as follow: Error in ==> absnoll2 at 80 [a]= MKA(x,y,deltay,1);
Thanks in advance! sorry for the typo..
Friendly Regards, Erik.
0 Kommentare
Akzeptierte Antwort
Star Strider
am 10 Apr. 2014
If you are testing for the column size of x, change the call to size to:
size(x,2)
(and for other arrays) in your if statements.
There may be other problems, but that should eliminate the error you are getting.
0 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Function Creation finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!