Statistics Fundamentals
Compute descriptive statistics, fit distributions, run hypothesis tests, and cluster data.
Step 1 — Descriptive statistics
Summarize data with mean, standard deviation, and percentiles.
data = randn(1, 1000); disp(mean(data)); disp(std(data)); disp(prctile(data, [25 50 75]))▶ Run in SimLab
Expected output: Mean near 0, std near 1, quartiles
Step 2 — Histogram
Visualize data distribution.
data = randn(1, 500);
histogram(data);
title('Normal Distribution Sample')▶ Run in SimLabExpected output: Bell-shaped histogram
Step 3 — Hypothesis testing
ttest() returns an object with t-statistic, p-value, degrees of freedom, and confidence interval.
sample = 5 + 0.5*randn(1, 30);
result = ttest(sample, 5);
printf('p-value: %.4f, t-stat: %.2f', result.p, result.t)▶ Run in SimLabExpected output: p-value and t-statistic
Step 4 — K-means clustering
Group 2D data into clusters.
rng(42);
x1 = randn(1, 50);
y1 = randn(1, 50);
x2 = 3 + randn(1, 50);
y2 = 3 + randn(1, 50);
scatter([x1, x2], [y1, y2]);
title('Two visible clusters')▶ Run in SimLabExpected output: Scatter plot with 2 visible clusters
Related Tutorials
Try SimLab — MATLAB®-compatible, free, in your browser
466 functions. Runs in your browser. No install.
Open SimLabMATLAB® is a registered trademark of The MathWorks, Inc. SimLab is an independent project by Simulations4All and is not affiliated with, endorsed by, or sponsored by The MathWorks, Inc.