MATLAB: Selecting random numbers

random number

i have a matrix 10×10 i want to select random matrix of 5×5 but the selected matrix must be in same order as the original matrix,if i choose 20×20 the random matrix must be 10×10
please help

Best Answer

Just use rand() to randomly pick a row and column in the range 1 to half the width and extract it subMatrix = fullMatrix(row1:row2, col1:col2); I'm sure you can figure out how to get row1, etc. using rand. (I'm leaving some of the work to you in case this is a homework problem, which it sounds like it is.)