% suppose we have two arrays of data: data1 and data2% n1 and n2 are sample sizes% alpha is the level of significance, typically 0.05% calculate means and standard deviationsmean1 = mean(data1);
mean2 = mean(data2);
std1 = std(data1);
std2 = std(data2);
% calculate the standard errorSE = sqrt((std1^2)/n1 + (std2^2)/n2);
% calculate the t-valuet = (mean1 - mean2) / SE;
% calculate the degrees of freedomdf = n1 + n2 - 2;
% calculate the critical t-valuet_critical = tinv(1-alpha/2, df);
% compare t with t_critical and reject or fail to reject null hypothesisif (abs(t) > t_critical)
disp('Reject null hypothesis');
elsedisp('Fail to reject null hypothesis');
end