How do I find the x and y coordinates of a fitted Gaussian curve at a given slope?
I have written a code that fits my data with a Gaussian curve. I need to be able to set a baseline for multiple images with the same defined parameter then caluclate the full width-half maximum and slope between the baseline and maximum for each curve. What I’m thinking is to define the baseline as the point where the slope of the curve is equal to -1 (or another value). There may be other ways to do this, but it just needs to be consistant over all trials.
My code is:
clear
I=3; sumon=0; %holds variable of images to be added%
for k=[7:9]; %loop to add images together%
on{k}=imread(sprintf(‘on_ %d.tif’,k)); %reads on files at _k%
on{k}=double(on{k}); %stores variable as 64 bit, double precision floating variable%
sumon=sumon+(on{k}); %adds image k to previous image%
end %end for loop%
on=sumon/I %averages images taken%
sumoff=0; I=3; %holds variable of images to be added%
for k=[4:6]; %loop to add images together%
off{k}=imread(sprintf(‘off_ %d.tif’,k));%reads on files at _k%
off{k}=double(off{k}); %stores variable as 64 bit, double precision floating variable%
sumoff=sumoff+(off{k}); %adds image k to previous image%
end %end for loop%
off=sumoff/I %averages images taken%
result=on-off %subtracts averaged off image from average on image%
imshow(result) %shows result%
% rotate
result=imrotate(result,-93,’bilinear’)
%crop image
result=imcrop(result, [100, 450, 800, 200])
%show image
imshow(result)
%% Plotting intensity vs x pixel index
vertsum = sum(result, 1)
vertsum =vertsum-max(vertsum)
% Set data points
[xData, yData] = prepareCurveData( [], vertsum );
% Set up fittype and options.
ft = fittype( ‘gauss2’ );
opts = fitoptions( ‘Method’, ‘NonlinearLeastSquares’ );
opts.Display = ‘Off’;
opts.Lower = [-Inf -Inf 0 -Inf -Inf 0];
opts.StartPoint = [0 301 300 0 601 300];
% Fit model to data.
[fitresult, gof] = fit( xData, yData, ft, opts );
% Plot fit with data.
figure( ‘Name’, ‘untitled fit 1’ );
h = plot( fitresult, xData, yData );
legend( h, ‘vertsum’, ‘Gaussian fit’, ‘Location’, ‘NorthEast’, ‘Interpreter’, ‘none’ );
% Label axes
ylabel( ‘vertsum’, ‘Interpreter’, ‘none’ );
grid on
I’ve also included a picture of the resulting curve. In this case I’d like the baseline to be set at ~150,-3, and the maximum at -350, -15. I already have it written to culculate the FWHM and slope between these points if I just manually set the baseline. Thanks!I have written a code that fits my data with a Gaussian curve. I need to be able to set a baseline for multiple images with the same defined parameter then caluclate the full width-half maximum and slope between the baseline and maximum for each curve. What I’m thinking is to define the baseline as the point where the slope of the curve is equal to -1 (or another value). There may be other ways to do this, but it just needs to be consistant over all trials.
My code is:
clear
I=3; sumon=0; %holds variable of images to be added%
for k=[7:9]; %loop to add images together%
on{k}=imread(sprintf(‘on_ %d.tif’,k)); %reads on files at _k%
on{k}=double(on{k}); %stores variable as 64 bit, double precision floating variable%
sumon=sumon+(on{k}); %adds image k to previous image%
end %end for loop%
on=sumon/I %averages images taken%
sumoff=0; I=3; %holds variable of images to be added%
for k=[4:6]; %loop to add images together%
off{k}=imread(sprintf(‘off_ %d.tif’,k));%reads on files at _k%
off{k}=double(off{k}); %stores variable as 64 bit, double precision floating variable%
sumoff=sumoff+(off{k}); %adds image k to previous image%
end %end for loop%
off=sumoff/I %averages images taken%
result=on-off %subtracts averaged off image from average on image%
imshow(result) %shows result%
% rotate
result=imrotate(result,-93,’bilinear’)
%crop image
result=imcrop(result, [100, 450, 800, 200])
%show image
imshow(result)
%% Plotting intensity vs x pixel index
vertsum = sum(result, 1)
vertsum =vertsum-max(vertsum)
% Set data points
[xData, yData] = prepareCurveData( [], vertsum );
% Set up fittype and options.
ft = fittype( ‘gauss2’ );
opts = fitoptions( ‘Method’, ‘NonlinearLeastSquares’ );
opts.Display = ‘Off’;
opts.Lower = [-Inf -Inf 0 -Inf -Inf 0];
opts.StartPoint = [0 301 300 0 601 300];
% Fit model to data.
[fitresult, gof] = fit( xData, yData, ft, opts );
% Plot fit with data.
figure( ‘Name’, ‘untitled fit 1’ );
h = plot( fitresult, xData, yData );
legend( h, ‘vertsum’, ‘Gaussian fit’, ‘Location’, ‘NorthEast’, ‘Interpreter’, ‘none’ );
% Label axes
ylabel( ‘vertsum’, ‘Interpreter’, ‘none’ );
grid on
I’ve also included a picture of the resulting curve. In this case I’d like the baseline to be set at ~150,-3, and the maximum at -350, -15. I already have it written to culculate the FWHM and slope between these points if I just manually set the baseline. Thanks! I have written a code that fits my data with a Gaussian curve. I need to be able to set a baseline for multiple images with the same defined parameter then caluclate the full width-half maximum and slope between the baseline and maximum for each curve. What I’m thinking is to define the baseline as the point where the slope of the curve is equal to -1 (or another value). There may be other ways to do this, but it just needs to be consistant over all trials.
My code is:
clear
I=3; sumon=0; %holds variable of images to be added%
for k=[7:9]; %loop to add images together%
on{k}=imread(sprintf(‘on_ %d.tif’,k)); %reads on files at _k%
on{k}=double(on{k}); %stores variable as 64 bit, double precision floating variable%
sumon=sumon+(on{k}); %adds image k to previous image%
end %end for loop%
on=sumon/I %averages images taken%
sumoff=0; I=3; %holds variable of images to be added%
for k=[4:6]; %loop to add images together%
off{k}=imread(sprintf(‘off_ %d.tif’,k));%reads on files at _k%
off{k}=double(off{k}); %stores variable as 64 bit, double precision floating variable%
sumoff=sumoff+(off{k}); %adds image k to previous image%
end %end for loop%
off=sumoff/I %averages images taken%
result=on-off %subtracts averaged off image from average on image%
imshow(result) %shows result%
% rotate
result=imrotate(result,-93,’bilinear’)
%crop image
result=imcrop(result, [100, 450, 800, 200])
%show image
imshow(result)
%% Plotting intensity vs x pixel index
vertsum = sum(result, 1)
vertsum =vertsum-max(vertsum)
% Set data points
[xData, yData] = prepareCurveData( [], vertsum );
% Set up fittype and options.
ft = fittype( ‘gauss2’ );
opts = fitoptions( ‘Method’, ‘NonlinearLeastSquares’ );
opts.Display = ‘Off’;
opts.Lower = [-Inf -Inf 0 -Inf -Inf 0];
opts.StartPoint = [0 301 300 0 601 300];
% Fit model to data.
[fitresult, gof] = fit( xData, yData, ft, opts );
% Plot fit with data.
figure( ‘Name’, ‘untitled fit 1’ );
h = plot( fitresult, xData, yData );
legend( h, ‘vertsum’, ‘Gaussian fit’, ‘Location’, ‘NorthEast’, ‘Interpreter’, ‘none’ );
% Label axes
ylabel( ‘vertsum’, ‘Interpreter’, ‘none’ );
grid on
I’ve also included a picture of the resulting curve. In this case I’d like the baseline to be set at ~150,-3, and the maximum at -350, -15. I already have it written to culculate the FWHM and slope between these points if I just manually set the baseline. Thanks! slope, gaussian MATLAB Answers — New Questions