Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Can you help me with this. We are supposed to pull random selected values from d

ID: 3587068 • Letter: C

Question

Can you help me with this. We are supposed to pull random selected values from dataSet and show them as an array in selected Values. This is MatLab

Selecting random elements from an array Use tha rand function and an ndeing anray Ex r numberSelected s 3 anc dataset s [74, 13.1, 51, 61, then selectedvalues might retum | 1, 74, 131, Assessment" rests re compared to produce the same random num Des Your Function Psave CReset ·MAI LAB Documentation i function selecteWalues selectRs"um detset, "unbeSelected} 2% selcctRandon: Return nunSel ale ents o! input array data sale cted at 5% randon . Duplicate selections dre acceptable 4 % Tnputs: data - array of tnnut data values nunScl number of randcnly selected clenents to return 7% Outputs : selected- rray al randonly selected data valus % Chaos. randnaly s@lerted elatents far utput dat aSct-rand(1,3 Code to call your function C Reset selectRancon( 74, 13, 1' 51. ), 3)

Explanation / Answer

function selectedValues = selectRandom(dataset,numberSelected)
% emptyr vector
selectedValues = [];
% for loop to add numberSelected elements to selectedValues
for i=1:numberSelected
% random interger in range of dataset length
index = randi(length(dataset));
% add element to selectedValues
selectedValues = [selectedValues, dataset(index)];
end
end

selectRandom([74,12,1,51,6],3)

% sample output
% ans =
%
% 74 6 51