


elementRandom: Select a random element from a matrix
Usage: [value, index] = elementRandom(mat)
Selects a random element from the matrix mat.
The returned index is always a scalar.

0001 function [value, index] = elementRandom(mat) 0002 %elementRandom: Select a random element from a matrix 0003 % Usage: [value, index] = elementRandom(mat) 0004 % 0005 % Selects a random element from the matrix mat. 0006 % The returned index is always a scalar. 0007 0008 % Roger Jang, 19960922 0009 0010 index = ceil(rand*prod(size(mat))); 0011 value = mat(index);