creating weighted sample for a matrix
이전 댓글 표시
I need to create a sample from an m by n matrix. Each row has a probability associated with it and can be treated as one observation. I need to draw N (the sample size) number of these rows based on their assigned probability. The problem is that randsample only takes a vector as input such as this example:
R = randsample([1 2 3], N, true, [0.5 0.25 0.25])
Whereas I need something like this:
R = randsample([1 2 3; 4 5 6; 7 8 9], N, true, [0.5 0.25 0.25])
So far I've not found an answer from Google, so I'd appreciate any pointers.
채택된 답변
추가 답변 (1개)
Sean de Wolski
2012년 5월 8일
0 개 추천
(Unless I'm missing something (which is certainly possible (probable))) This could easily be done with a for-loop.
카테고리
도움말 센터 및 File Exchange에서 Piecewise Linear Distribution에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!