MATLAB: How do i select random indicies from an array array I have an array of 10 by 6. is there a way I can randomly select rows from this particular array and everything within it. Best Answer Let's say you have a 10-by-6 matrix m, and you want to select 7 rows at random and make sure there are no repeats. Do this:m = randi(9, 10,6)randomRows = randperm(size(m, 1), 7)randomRows is the array of row numbers , not the actual 6 element rows themselves. Related SolutionsMATLAB: How to select a random element in a row of matrix Try this:yourMatrix = magic(9) % Sample datarandomColumnNumber = randi(size(yourMatrix, 2), 1)row = 3; % Whatever% Get the value of the matrix at this location.randomValueInRow = yourMatrix(row, randomColumnNumber) MATLAB: Finding multiple first or last indicies x = [1;1;1;0;0;1;1;0;1;0;0;1]s = [0, x.'];result1 = strfind(s, [0, 1])result2 = result1(2:end) - 1 Related QuestionRandom elements from specific rows in matrixHow to loop on multiple indiciesHow to subset rows with reproducibilitySelecting random number from martrixFind indicies of k smallest matrix elements
Best Answer