0% found this document useful (0 votes)
5 views

Statistical Analysis in MATLAB (2)

The document discusses generating random numbers using uniform and normal distributions, as well as the linear congruential method. It covers statistical calculations such as mean, standard deviation, and correlation coefficients, along with various data visualization techniques like histograms and different types of plots. Additionally, it provides examples of generating random numbers and performing statistical analysis using programming functions.

Uploaded by

kkirbiyik7
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

Statistical Analysis in MATLAB (2)

The document discusses generating random numbers using uniform and normal distributions, as well as the linear congruential method. It covers statistical calculations such as mean, standard deviation, and correlation coefficients, along with various data visualization techniques like histograms and different types of plots. Additionally, it provides examples of generating random numbers and performing statistical analysis using programming functions.

Uploaded by

kkirbiyik7
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

 Generating random numbers

 Uniform distribution
 Normal distribution
 Linear congruential method

 Finding the mean and standard deviation of a data set


 Using while loop
 Using for loop
 Using mean, std, var

 Other statistics: corrcoef, cov, max, median, min, mode


 Plotting the histogram of a data set
 Using different chart types to represent data
 Bar plots
 Pie plots
 Stem plots
 Stair plots 2
%Examples on the use of random (pseudorandom) numbers
%Generate a uniform random number between 0 and 1
R = rand
%Generate a 3 by 3 matrix of random numbers between 0 and 1
R = rand(3)
%Generate a 3 by 2 matrix of random numbers
R = rand(3,2)
%Generate an m by n by p by... matrix of random numbers
%R = rand(m,n,p,...)
%Generate uniform random numbers between 0 and 60:
R = 60.*rand(10,1)
%Generate uniform random integers between 0 and 60:
R = ceil(60.*rand(10,1))
%Generate uniform random numbers between a and b:
a = 10; b = 60;
R = a + (b-a)*rand(100,1)

3
%Examples on the use of random (pseudorandom) numbers
%Generate a standard normal random number (mean=0, std=1)
R = randn
%Generate a 3 by 3 matrix of standard normal random numbers
R = randn(3)
%Generate a 3 by 2 matrix of standard normal random numbers
R = randn(3,2)
%Generate an m by n by p by... matrix of standard normal random numbers
%R = randn(m,n,p,...)
%Generate standard normal random numbers with specific mean and variance:
meanR = 0.6; varR = 0.1;
R = meanR + sqrt(varR) * randn(4)

4
function x = LinConGen(m,a,c,x0,n)
% Returns the linear congruential sequence

x=zeros(1,n);% initialize an array of zeros


x(1)=x0;

for i = 2:n % loop to generate the Linear Congruential sequence


x(i)=mod(a * x(i-1) + c, m);
end

5
%Generate uniform random M =
numbers between a and b:
a = 10; b = 60; 33.4878

R = a + (b-a)*rand(100,1) Me =

34.3208
M = mean(R)
Mo =
Me = median(R) 10.5168
Mo = mode(R)
S =

S = std(R) 13.8899
V = var(R)
V =

192.9298 6
x = randn(30,4); % Uncorrelated data
x(:,4) = sum(x,2); % Introduce correlation.

[r,p] = corrcoef(x) % Compute sample correlation and p-values.


%returns a matrix of p-values for testing the hypothesis of no
correlation
[i,j] = find(p<0.05) % Find significant correlations

7
%hist(x,y) plots the histogram of values in x in
length(y) bins with centers specified by y.
%To close all open figures: y = [25,45,55,65,75,85,95,125]
close all figure(2), hist(x,y)
%histc(x,y) returns number of values in vector x
%Use the LinConGen function to generate 1000 that fall between the elements in y (must be
random values: monotonically nondecreasing values).
x = LinConGen(137,25,16,86,1000) [n, bin] = histc(x,y)
%Find the cumulative number of elements:
%You can find the mean and standard
deviation of the random values: cumulative_n = cumsum(n)
mean(x) %The cumulative histogram:
std(x)
figure(3), bar(y,cumulative_n)
%[n,xout] = hist(...) returns vectors n and xout
%hist(x) plots the histogram of x in 10 containing the frequency
bins.
%hist(x,n) plots the histogram of x in n %counts and the bin locations.
bins.
[n, xout] = hist(x,20)
figure(1), subplot(2,1,1), hist(x)
figure(4), subplot(2,1,1), bar(xout,n)
subplot(2,1,2), hist(x,20)
subplot(2,1,2), barh(xout,n)

You might also like