Azzera filtri
Azzera filtri

How to measure mean and standard deviation according to bin size?

6 visualizzazioni (ultimi 30 giorni)
I have 1 to 144 columns.
I want to know the standard deviation and mean value according to the bin size when performing Gaussian fitting for 144 columns.
I want to measure the value when 'bin size=50'.

Risposte (1)

MULI
MULI il 20 Feb 2024
You can follow these steps to know the mean value and standard deviation according to bin size.
  1. Take each of the 144 columns of data individually.
  2. Create a histogram of data in each column using a bin size of 50.
  3. Fit a Gaussian distribution to each histogram.
  4. Extract the mean and standard deviation from each fitted Gaussian distribution.
clc;
clear all;
close all;
% Define the URL of the data file
url = 'https://in.mathworks.com/matlabcentral/answers/uploaded_files/833625/1to10_30s_15mm_diff_pivoted.txt';
% Download the data file
filename = websave('localdata.txt', url);
% Load the data into MATLAB using readmatrix
data = readmatrix(filename);
% Define the number of columns and bin size
nColumns = 144;
binSize = 50;
% Preallocate arrays for means and standard deviations
means = zeros(1, nColumns);
stdDevs = zeros(1, nColumns);
% Loop through each column to perform Gaussian fitting
for col = 1:nColumns
columnData = data(:, col); % Extract data for the current column
% Create histogram bins with the specified bin size
binEdges = min(columnData):binSize:max(columnData);
binCenters = binEdges(1:end-1) + binSize/2;
binCounts = histcounts(columnData, binEdges);
% Fit a Gaussian distribution to the binned data
% Define Gaussian function (normal distribution)
gaussEqn = 'a*exp(-((x-b)/c)^2)';
startPoints = [max(binCounts), mean(columnData), std(columnData)]; % Initial guess
% Perform the fit
fitObject = fit(binCenters(:), binCounts(:), gaussEqn, 'Start', startPoints);
% Extract the mean and standard deviation from the fit parameters
means(col) = fitObject.b;
stdDevs(col) = abs(fitObject.c); % Ensure standard deviation is positive
end
% Display the results
disp('Means of Gaussian fits for each column:');
disp(means);
disp('Standard deviations of Gaussian fits for each column:');
disp(stdDevs);

Prodotti

Community Treasure Hunt

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

Start Hunting!

Translated by