nlinfit command problem :(
10 ビュー (過去 30 日間)
古いコメントを表示
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 件のコメント
Stephen23
2021 年 1 月 16 日
編集済み: Stephen23
2021 年 1 月 16 日
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?? :(
採用された回答
Steven Lord
2021 年 1 月 16 日
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 件のコメント
Steven Lord
2021 年 1 月 16 日
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);
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Correlation Models についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!