Problem with a matrix question
1 view (last 30 days)
The find command can be used on large sets of data to make extraction easy. The command rand generates pseudorandom numbers that are between 0 and 1 in a standard uniform distribution.
a3 = round(100*rand(10,12),0)
b3 = mean(a3)
NOTE: the command rng allows the ‘random’ number to be set to always be the same and will be the same for all students (the number is called the ‘seed’). Set the seed to (081518) and rerun. Using the original seed value, extract all numbers greater than or equal to 48 from the matrix and create a 2 x (n/2) matrix containing the newly extracted values with the first half in the first row and the second half in the second row (n is the length of vector with the indexed values >= 48).
Can someone please help me to understand how this works?
Kritika Bansal on 12 Sep 2019
rng(seed) is used to control the random number generating functions like rand(), randi(), randn() in MATLAB
rand(m,n) generates a matrix of mxn with random numbers with values lying in the interval (0,1)
round(A, 0) rounds the values in A to nearest integer
mean(A) returns the mean of the matrix A along first dimension
To accomplish what you’re asking for, you can run the following commands in MATLAB after running the code provided by you:
indices = find(a3>=48); %finds the indices of values >= 48
a4 = a3(indices); %extracts the values >=48 into a4
a5 = zeros(2, length(indices)/2); %creates a matrix full of zeros with the given dimensions
a5(1,:) = a4(1:length(indices)/2); %fills in the first row
a5(2,:) = a4(length(indices)/2 + 1: end); %fills in the second row
To know more about the functions used above, you can refer to the links given below: