In: Computer Science
The following code must be written using matlab and must be using a for-loop. NOTE!
Write a computer program that assigns random integers for each entry and generates a row vector. Different random integers should be drawn from different intervals in chunks of 4 , that is chunk1-chunk2-chunk3-chunk4 The parameters for specifying the lintervals by which the random numbers should be drawn should be able to change and be hardcoded in the script, however, be hardcoded in the script.
Complete code in Matlab:-
% Creating 4 chunks, 'chunk1', 'chunk2', 'chunk3', chunk4'
chunk1 = [10, 100];
chunk2 = [1000, 1100];
chunk3 = [11000, 12000];
chunk4 = [120000, 130000];
% Creating an empty row vector.
numbers = [];
% 'n' is defining the count of random numbers to be generated from each chunk.
% Total Random number will be generated 4*n.
% You have not specified the length of row vector of random integers
% So I am defining it manually.
n = 10;
% Generating 4*n random numbers.
for i=[1:n]
% Picking a random number from 'chunk1'
numbers = [numbers, randi(chunk1, 1, 1)];
% Picking a random number from 'chunk2'
numbers = [numbers, randi(chunk2, 1, 1)];
% Picking a random number from 'chunk3'
numbers = [numbers, randi(chunk3, 1, 1)];
% Picking a random number from 'chunk4'
numbers = [numbers, randi(chunk4, 1, 1)];
end
display(numbers);
Screenshot of output:-