MATLAB: Randomly select a number from a matrix

random number selection

Hi all. I have a 365×27 matrix of values where the rows are the different days of a year (365) and the columns the number of years that I am considering (27). What I would like to do is to create a vector 365×1 where every day one value is randomly selected from the initial matrix. So, for the first day the function should randomly select a value out of the first row of the inital matrix, for the second day a value randomly taken from the second row of the inital matrix and so on. Does someone know how to do it? Thanks

Best Answer

indexarray=randi(27,365,1);
For k=1:365
Vector(k)=Matrix(k,indexarray(k,1));
end
Best wishes
Torsten.