3. Read about the sortrows function in MATLAB\'s help documentation and then wri
ID: 3758969 • Letter: 3
Question
3. Read about the sortrows function in MATLAB's help documentation and then write a script that creates a 10x5 matrix of random values between 0 and 10 and then sorts it using sortrows. 4. Write a single line of MATLAB code that computes the mean and standard deviation of a 1-dimensional array named A of numbers. You may not use loops, or the mean, variance, or stdev functions. Assume the array A has already been defined. The mean is the arithmetic average of the values in the array, mu = 1/n summation i = 1 to n ai. The variance is the arithmetic average of the squared difference between each value and the mean, sigma^2 = 1/n - 1 summation i = 1 to n (ai - mu)^2. The standard deviation is the square root of the variance, sigma = rootsigma^2..Explanation / Answer
array = zeros(10,5)
for i = 1 : 10
% generate random integers beween 0 to 10 (inclusive)
array(i, : ) = randperm(11,5)-1;
end
disp("Array before sorting")
disp(array)
sortarray = sortrows(array)
disp("Array after row sorting")
disp(sortarray)
--------output----------------
Executing the program....
$octave -qf --no-window-system main.m
array =
0 0 0 0 0
0 0 0 0 0
0 0 0 0 0
0 0 0 0 0
0 0 0 0 0
0 0 0 0 0
0 0 0 0 0
0 0 0 0 0
0 0 0 0 0
0 0 0 0 0
Array before sorting
6 2 5 3 0
7 6 2 5 3
6 1 3 8 7
9 1 6 8 7
8 10 0 5 7
10 9 8 0 2
4 8 3 9 1
4 5 6 9 0
1 2 9 10 7
3 7 0 10 9
sortarray =
1 2 9 10 7
3 7 0 10 9
4 5 6 9 0
4 8 3 9 1
6 1 3 8 7
6 2 5 3 0
7 6 2 5 3
8 10 0 5 7
9 1 6 8 7
10 9 8 0 2
Array after row sorting
1 2 9 10 7
3 7 0 10 9
4 5 6 9 0
4 8 3 9 1
6 1 3 8 7
6 2 5 3 0
7 6 2 5 3
8 10 0 5 7
9 1 6 8 7
10 9 8 0 2
---------------------Question 4-------------------------------------------------
% randome integers in [1 to 20]
data = randperm(20,5);
disp(data)
%mean
meanOfData = sum(data) / length(data)
%s.d
sd = power(sum((data .- meanOfData).^2), 1/2)
disp(sd)
9 11 13 20 19
meanOfData = 14.400
sd = 9.7570
9.7570
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.