% Define Gaussian function
gaussian = @(params,x) params(1) * exp(-(x - params(2)).^2 / (2*params(3)^2));

% Initialize parameters for Gaussian model
params0 = [10, 0, 1];

% Initialize arrays to store peak heights, positions, and widths
heights = zeros(1,10);
positions = zeros(1,10);
widths = zeros(1,10);

% Generate signal with Gaussian peak and noise, fit Gaussian model, and store peak parameters
for i = 1:10
    % Generate signal with Gaussian peak and random noise
    x = linspace(-10,10,100);
    y = gaussian(params0,x) + 2*randn(1,100);
    
    % Fit Gaussian model to data using fminsearch
    params = fminsearch(@(params) norm(y - gaussian(params,x)), params0);
    
    % Store peak height, position, and width
    heights(i) = params(1);
    positions(i) = params(2);
    widths(i) = params(3);
end

% Compute mean and standard deviation of peak heights, positions, and widths
mean_height = mean(heights);
std_height = std(heights);
mean_position = mean(positions);
std_position = std(positions);
mean_width = mean(widths);
std_width = std(widths);

disp(['Mean height: ',num2str(mean_height),' +/- ',num2str(std_height)])
disp(['Mean position: ',num2str(mean_position),' +/- ',num2str(std_position)])
disp(['Mean width: ',num2str(mean_width),' +/- ',num2str(std_width)])
