I have a 2d matrix as follows:
possibleDirections =
1 1 1 1 0
0 0 2 2 0
3 3 0 0 0
0 4 0 4 4
5 5 5 5 5
I need from every column to get a random number from the values that are non-zero in to a vector. The value 5 will always exist so there won't be any columns with all zeros. Any ideas how this can be achieved with the use of operations on the vectors (w/o treating each column separately)? An example result would be [1 1 1 1 5]
Thanks
randi(mathworks.com/help/matlab/ref/randi.html) function does not accept a vector of integers for different ranges. - Andrew Mao