nlinfit command problem :(
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Enes Emre Öztürk
el 16 de En. de 2021
A gaussfit code gives an error of:
Error using nlinfit>checkWeights (line 961)
Weights must be a vector of real positive weights or a function handle that accepts a vector of
predicted response values and returns a vector of real positive weights the same size as Y.
Error in nlinfit (line 223)
nanweights = checkWeights(weights, yfit, y);
Error in Nonlinearhw (line 8)
plot(q,Astart,'-k'); [beta,R,J,covB]=nlinfit(q,A,'gaussfit',n,'Weights',dA);
Also q and A both are 161*1 matrixes.
What is the problem?? :(
1 comentario
Stephen23
el 16 de En. de 2021
Editada: Stephen23
el 16 de En. de 2021
Original question by Enes Emre Öztürk:
nlinfit command problem :(
clc; clear all; close all;
[verim]=specokuma('HWdata.spc',403);
q=verim(:,1);A=verim(:,end);
B=q+A;dA=sqrt(verim(:,end));
figure(1);hold on; errorbar(q,A,dA,'og');
n=[1000 8 0.01 1000];
[Astart]= gaussfit(n,q); hold on;
plot(q,Astart,'-k'); [beta,R,J,covB]=nlinfit(q,A,'gaussfit',n,'Weights',dA);
[Afit]=gaussfit(beta,q);
plot(q,Afit,'-r','Linewidht',3);
And gaussfit function is:
function [Afit]=gaussfit(n,X)
Amp=abs(n(1));
Xc=n(2);
width=abs(n(3));
backgnd=(n(4)); %yb=n(4)+n(5)X
%Afit=(n(1)*exp(-1*(X-n(2)).^2/(n(3)^2))+n(4));
Afit=(Amp*exp(-1*(X-Xc).^2/(width^2))+backgnd);
İt gives an error of:
Error using nlinfit>checkWeights (line 961)
Weights must be a vector of real positive weights or a function handle that accepts a vector of
predicted response values and returns a vector of real positive weights the same size as Y.
Error in nlinfit (line 223)
nanweights = checkWeights(weights, yfit, y);
Error in Nonlinearhw (line 8)
plot(q,Astart,'-k'); [beta,R,J,covB]=nlinfit(q,A,'gaussfit',n,'Weights',dA);
Also q and A both are 161*1 matrixes.
What is the problem?? :(
Respuesta aceptada
Steven Lord
el 16 de En. de 2021
From the error message: "Weights must be a vector of real positive weights ..." Are they?
- Is dA a vector? Check with isvector.
- Is dA a real vector? Check with isreal.
- Are all the elements in dA positive? Check using the > operator. Remember that 0 is not positive.
1 comentario
Steven Lord
el 16 de En. de 2021
Since the poster edited away most of the code (please don't do that in the future, it can make the answer to the question useless for people trying to solve the same problem in the future) one of the lines in the error stack lists the line of code that told me dA was the vector being specified as the weights.
Error in nlinfit (line 223)
nanweights = checkWeights(weights, yfit, y);
Error in Nonlinearhw (line 8)
plot(q,Astart,'-k'); [beta,R,J,covB]=nlinfit(q,A,'gaussfit',n,'Weights',dA);
Más respuestas (0)
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!