randomly select a number from a matrix
이전 댓글 표시
Hi all. I have a 365x27 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 365x1 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
채택된 답변
추가 답변 (1개)
Andrei Bobrov
2015년 5월 19일
편집: Andrei Bobrov
2015년 5월 19일
n = size(Matrix);
out = Matrix(sub2ind(n,(1:n(1))',randi(n(2),n(1),1)));
카테고리
도움말 센터 및 File Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!