Mercurial > hg > ltpda
comparison m-toolbox/classes/+utils/@math/wfun.m @ 0:f0afece42f48
Import.
author | Daniele Nicolodi <nicolodi@science.unitn.it> |
---|---|
date | Wed, 23 Nov 2011 19:22:13 +0100 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:f0afece42f48 |
---|---|
1 % WFUN defines weighting factor for fitting procedures ctfit, dtfit. | |
2 % | |
3 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
4 % | |
5 % DESCRIPTION | |
6 % | |
7 % Defines the weigthing factor for the fitting procedure performed by | |
8 % ctfit and dtfit. | |
9 % | |
10 % CALL: | |
11 % | |
12 % weight = wfun(y,weightparam) | |
13 % | |
14 % INPUT: | |
15 % | |
16 % y: are the set of data to be fitted | |
17 % weightparam: is a parameter for the swhitching procedure. Admitted | |
18 % values are: | |
19 % weightparam = 1 --> equal weights (one) for each point. This is the | |
20 % default option. | |
21 % weightparam = 2 --> weight with the inverse of absolute value of | |
22 % data | |
23 % weightparam = 3 --> weight with square root of the inverse of | |
24 % absolute value of data | |
25 % weightparam = 4 --> weight with the inverse of the square mean | |
26 % spread | |
27 % | |
28 % | |
29 % OUTPUT: | |
30 % | |
31 % weight: is the set of weighting factors | |
32 % | |
33 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
34 % VERSION: $Id: wfun.m,v 1.5 2008/11/17 16:52:23 luigi Exp $ | |
35 % | |
36 % HISTORY: 08-10-2008 L Ferraioli | |
37 % Creation | |
38 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
39 | |
40 function weight = wfun(y,weightparam) | |
41 | |
42 [a,b] = size(y); | |
43 | |
44 opt = 0; % default value | |
45 if ~isempty(weightparam) | |
46 opt = weightparam; | |
47 end | |
48 | |
49 switch opt | |
50 case 0 | |
51 disp(' Using external weights... ') | |
52 case 1 | |
53 weight = ones(a,b); % equal weights for each point | |
54 case 2 | |
55 weight = 1./abs(y); % weight with the inverse of absolute value of data | |
56 case 3 | |
57 weight = 1./sqrt(abs(y)); % weight with square of the inverse of absolute value of data | |
58 case 4 | |
59 my = mean(y,max(a,b)); | |
60 weight = 1./((y-my).^2); % weight with the inverse of the square mean spread | |
61 end |