Specifying a position of a Gaussian fit

Please how can I specify where my gaussian should be fitted on a data plot
Below is my matlab code and attahed are my sample plot with the data.
clear; clc;
thisfile = pwd + "\matlabdata.txt\";
Txtdata = load(thisfile);
x = Txtdata(:, 1);
y = Txtdata(:, 2);
inc=~isnan(y);
hgt = find(isnan(y));
gEqn = 'a*exp(-((x-b)/c)^2)+d';
startPoints = [5 0 10 2];
[fj,gof,output] = fit(x,y,gEqn,'Start', startPoints, 'Exclude', hgt);%,'Start', startPoints, 'Exclude', [1 10 25]
plot(fj,x,y)
The blue line is anexample of my desired Gaussian.
Its more of shifting a little bit the centre of the Gaussian side ways. I do not know if its possible
Thanks

1 Comment

Seems to me you want to "shape" your gaussian curve , not simply shift it
you have to first define which model would better fullfill your task

Sign in to comment.

 Accepted Answer

Seems like you blew past the posting guidelines. If you have any more questions, then attach 'matlabdata.txt' with the paperclip icon after you read this:
In the meantime see histfit
rng default; % For reproducibility
r = normrnd(10,1,1000,1);
pd = fitdist(r,'Normal')
pd =
NormalDistribution Normal distribution mu = 9.96737 [9.90538, 10.0294] sigma = 0.998965 [0.957021, 1.04478]
% Construct a histogram with a normal distribution fit.
plotParameters = histfit(r)
plotParameters =
2×1 graphics array: Bar Line
grid on

5 Comments

I saw this before. This is not what I want.
Thank you
If you don't want the center as determined by the fit then you can specify some fixed location and use nlmfit. I attach a demo but you'll need to adapt it to make the mean what you want it to be rather than having the fit decide where it should be. If you can't figure it out, let me know. And let me know the value of the desired location of the peak of the Gaussian, like -2 or whatever you want.
Thank you very much for trying to help me out
I'll give you feedback here.
TTA
TTA on 22 Dec 2022
Moved: Image Analyst on 23 Dec 2022
Hi @Image Analyst, I have tried but still could not achieve what I want. I just wondering if its possible to achieve the black sketched line in the figure below. I also attached my code.
thanks
What makes you think the black curve is better or more accurate than the red curve?
Maybe you should fit a different formula, like a Rayleigh or something. What is the theory behind this experiment? What formula does theory say your data should follow? In the middle range it just seems like total noise - a shotgun blast - like it follows no theoretical distribution whatsoever.

Sign in to comment.

More Answers (0)

Categories

Find more on Interpolation of 2-D Selections in 3-D Grids in Help Center and File Exchange

Asked:

TTA
on 21 Dec 2022

Commented:

on 23 Dec 2022

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!