fitting exponential decay help
Hi everyone,
Looking for a little bit of guidance for finding a lifetime decay for a 256×344 image. I think I’m pretty much there, but need some help. I was given the NLFit file to use for the fitting with the hint of using "fminsearch(‘NLfit1’,[y(end), 1, 1], [], delay*1e-3 – t0, data1" to find my fitting. However data1 is a matrix, and after some digging it seems I need to use an anonymous function?
I only started to use MATLAB about a week ago so I’m very new. Any help would be appreciated. I’ve attached the function file. Here is my current code:
%import function
import NLfit1.*
% Read file
load(‘test.mat’);
global FitResults
Tot_intensity = sum(Image_matrix, 3);
% Find the maximum intensity in the image
max_intensity = max(Tot_intensity, [], ‘all’);
% find threshold
twenty_percent_of_max = 0.2 * max_intensity;
% create a new image where all pixels below the threshold are set to zero
filtered_img = Tot_intensity;
filtered_img(Tot_intensity < twenty_percent_of_max) = 0;
%restricting image from 6000ps to 10000ps. Normally I would use a logical
%operator here but this was also a simple solution
delay(delay < 6000) = [];
delay(delay > 10000) = [];
%declare empty matrix
lifetime_image = zeros(256, 344);
x0 = 0;
%iterate over the image
for x = 1:size(filtered_img, 1) % rows
for y = 1:size(filtered_img, 2) %columns
% only finding the lifetime constant for those pixels that are
% above the 20% threshold we set
if filtered_img(x, y) > 0
temporal_decay_curve = squeeze(Image_matrix(x, y, :));
decay_constant = fminsearch(@(temporal_decay_curve)NLfit1([y(end), 1, 1], delay*1e-3 – 5.5, temporal_decay_curve), x0);
lifetime_image(x, y) = decay_constant;
end
end
end
% plot!
figure;
colormap(gray)
imagesc(lifetime_image);Hi everyone,
Looking for a little bit of guidance for finding a lifetime decay for a 256×344 image. I think I’m pretty much there, but need some help. I was given the NLFit file to use for the fitting with the hint of using "fminsearch(‘NLfit1’,[y(end), 1, 1], [], delay*1e-3 – t0, data1" to find my fitting. However data1 is a matrix, and after some digging it seems I need to use an anonymous function?
I only started to use MATLAB about a week ago so I’m very new. Any help would be appreciated. I’ve attached the function file. Here is my current code:
%import function
import NLfit1.*
% Read file
load(‘test.mat’);
global FitResults
Tot_intensity = sum(Image_matrix, 3);
% Find the maximum intensity in the image
max_intensity = max(Tot_intensity, [], ‘all’);
% find threshold
twenty_percent_of_max = 0.2 * max_intensity;
% create a new image where all pixels below the threshold are set to zero
filtered_img = Tot_intensity;
filtered_img(Tot_intensity < twenty_percent_of_max) = 0;
%restricting image from 6000ps to 10000ps. Normally I would use a logical
%operator here but this was also a simple solution
delay(delay < 6000) = [];
delay(delay > 10000) = [];
%declare empty matrix
lifetime_image = zeros(256, 344);
x0 = 0;
%iterate over the image
for x = 1:size(filtered_img, 1) % rows
for y = 1:size(filtered_img, 2) %columns
% only finding the lifetime constant for those pixels that are
% above the 20% threshold we set
if filtered_img(x, y) > 0
temporal_decay_curve = squeeze(Image_matrix(x, y, :));
decay_constant = fminsearch(@(temporal_decay_curve)NLfit1([y(end), 1, 1], delay*1e-3 – 5.5, temporal_decay_curve), x0);
lifetime_image(x, y) = decay_constant;
end
end
end
% plot!
figure;
colormap(gray)
imagesc(lifetime_image); Hi everyone,
Looking for a little bit of guidance for finding a lifetime decay for a 256×344 image. I think I’m pretty much there, but need some help. I was given the NLFit file to use for the fitting with the hint of using "fminsearch(‘NLfit1’,[y(end), 1, 1], [], delay*1e-3 – t0, data1" to find my fitting. However data1 is a matrix, and after some digging it seems I need to use an anonymous function?
I only started to use MATLAB about a week ago so I’m very new. Any help would be appreciated. I’ve attached the function file. Here is my current code:
%import function
import NLfit1.*
% Read file
load(‘test.mat’);
global FitResults
Tot_intensity = sum(Image_matrix, 3);
% Find the maximum intensity in the image
max_intensity = max(Tot_intensity, [], ‘all’);
% find threshold
twenty_percent_of_max = 0.2 * max_intensity;
% create a new image where all pixels below the threshold are set to zero
filtered_img = Tot_intensity;
filtered_img(Tot_intensity < twenty_percent_of_max) = 0;
%restricting image from 6000ps to 10000ps. Normally I would use a logical
%operator here but this was also a simple solution
delay(delay < 6000) = [];
delay(delay > 10000) = [];
%declare empty matrix
lifetime_image = zeros(256, 344);
x0 = 0;
%iterate over the image
for x = 1:size(filtered_img, 1) % rows
for y = 1:size(filtered_img, 2) %columns
% only finding the lifetime constant for those pixels that are
% above the 20% threshold we set
if filtered_img(x, y) > 0
temporal_decay_curve = squeeze(Image_matrix(x, y, :));
decay_constant = fminsearch(@(temporal_decay_curve)NLfit1([y(end), 1, 1], delay*1e-3 – 5.5, temporal_decay_curve), x0);
lifetime_image(x, y) = decay_constant;
end
end
end
% plot!
figure;
colormap(gray)
imagesc(lifetime_image); function, curve fitting MATLAB Answers — New Questions