11 views (last 30 days)

hi...i have some scatter points in x-y coordinate.how can curve fitting without using of cftool?i want do it by gussian fitt but in gussian code there are x and y.i domt know how obtain them!

% f = fit(x,y,'gauss8'); % plot(f,x,y); % coeff=fit(x,y,ft);

G is sample matrix with 106*47 in size and meanValue is mean of columns in matrix.result matrix is 1*47 that it is scatter points.

meanValue = mean(G)

thank you

Star Strider
on 17 May 2014

Here’s my version of Gauss1 using fminsearch:

% % Single Gaussian Regression

% % Generate x- and y- data:

% x = linspace(0,10); % Generate x-data

% Normal distribution — b(1) = mean, b(2) = std

N = @(b,x) exp(-((x-b(1)).^2)./(2*b(2)^2)) ./ (b(2)*sqrt(2*pi));

% b = [5; 1];

% d1 = N(b,x); % Generate smooth y-data

% d2 = d1 + 0.05*(rand(size(d1))-.5); % Add noise

% % ————— Assign your variables to x and y here —————

x = your independent variable

y = your dependent variable

% % Use ‘fminsearch’ to do regression:

y = d2;

OLS = @(b) sum((N(b,x) - y).^2); % Ordinary Least Squares cost function

opts4 = optimset('MaxFunEvals',50000, 'MaxIter',10000);

B = fminsearch(OLS, rand(2,1))

Nfit = N(B,x); % Calculate estimated fit

The variables you need to have in your workspace are x and y (or assign them to x and y) to use this without modifying the code. The single ‘%’ commented lines are there for illustration. (Uncomment them if you want to see how it works. Remove them if you don’t need them.)

Image Analyst
on 29 Jun 2014

Sign in to comment.

Image Analyst
on 17 May 2014

How about polyfit. I've attached a demo.

Sign in to comment.

Sign in to answer this question.

Opportunities for recent engineering grads.

Apply Today
## 1 Comment

## Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/129941-how-can-curve-fitting#comment_214255

⋮## Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/129941-how-can-curve-fitting#comment_214255

Sign in to comment.