Hello, I am trying to generate a row of 3 random integers located within the array above. How can I tell my code to only pull numbers from the data set instead of all numbers in between?
I also tried this but it doesn't run correctly because it only recognizes scalar values. randi(dataSet(1:end),1,numberSelected)Alternatively, if you're not constrained to use randi, just use randsample instead (the randsample(population, k) syntax looks very much like your selectRandom syntax)..
selectRandom([ 74, 13, 1, 51, 6 ], 3) selectRandom([ 74, 13, 1, 51, 6 ], 4) function selectedValues = selectRandom( dataSet, numberSelected ) selectedValues = dataSet(randi(numel(dataSet), 1, numberSelected));Find the treasures in MATLAB Central and discover how the community can help you!
An Error Occurred
Unable to complete the action because of changes made to the page. Reload the page to see its updated state.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.