MATLAB program which computes the mean and standard deviation of the data. Use FOR LOOPs.
Posted in matlab
No comments
Thursday, August 7, 2014 By Anonymous
We
can generate a set of data with a random values about some
mean
value with the command
num=100;
spr=0.1;
data=5.0+spr*sign(1.0-2.0*rand(1,num)).*rand(1,num)
a) What is the last line doing?
b)
Write a MATLAB program which computes the mean and standard deviation of the data.
Use FOR LOOPs.
Solution:
function Question9()
num = 100;
spr = 0.1;
data = 5.0 + spr * sign(1.0 - 2.0 *
rand(1,num)) .* rand(1,num); %according
to as per given
Total=0;
Size = size(data);
for i=1 : Size(2)
Total = Total + data(i);
end
Mean = Total/num; %getting mean
Sum = 0;
for i=1 : Size(2)
Sum = Sum + ((data(i) - Mean) ^ 2);
end
SD = sqrt(Sum / (num-1));
fprintf('Mean of
Data: %.2f \n', Total/num);
fprintf('SD of data
%.2f \n', SD); %printig output
end
Related posts
- MATLAB function that takes a matrix as argument and then ask from the user
- MATLAB program which computes the mean and standard deviation of the data. Use FOR LOOPs.
- Plot the following MATLAB functions y = ln(exp(x^-1)) with x = 1, 1.5, 2, ..., 4
- Plot the following MATLAB functions: y = exp(-x^2) with x = 0, 0.1, 0.2, ..., 2
- Plot the following MATLAB functions: y = 3x+2 with x = 0, 0.25, 0.5, ...., 7.75, 8
Share this post
0 comments: