Thursday, August 29, 2019

MATLAB exercises - #1

First part of MATLAB practice exercises

  1. Generate random data for testing purpose
  2. Output mean and standard deviation of the data
  3. Plot histogram of the data

Part 1.

Generate random data:

  • using uniform distribution rand()
  • using normal distribution randn()

Using uniform distribution:

x_uniform = rand(100,1); % creates vector of 100 elements samples from uniform distribution, 0<=x<=1

Using uniform distribution:

x_normal = randn(100,1); % creates vector of 100 elements samples from normal distribution

Part 2.

Output mean of x_uniform:

mean(x_uniform)

Now, output mean of x_normal:

Show answer
mean(x_normal)

Output standard deviation of x_uniform:

std(x_uniform)

Now, output standard deviation of x_normal:

Show answer
mean(x_normal)

Part 3.

Plot histogram of the data using hist()function. Do it for both data vectors (random data from uniform and normal distributions)

Show answer
x_uniform = randn(100,1);
hist(x_uniform)