Generating 15 random values (array of 1x15 dim) whose sum equal to 1.

조회 수: 1 (최근 30일)
Sultan
Sultan 2017년 9월 28일
편집: Sultan 2017년 9월 29일
How I can generate a random vector v = [v1, ..., v15] such that v1+...+v15 = 1. Please help me. :MSA

답변 (1개)

John D'Errico
John D'Errico 2017년 9월 28일
편집: John D'Errico 2017년 9월 28일
1. Download randfixedsum from the file exchange.
2. Use it.
Do NOT generate a set of random numbers, then just scale them to sum to 1.
  댓글 수: 1
Sultan
Sultan 2017년 9월 29일
편집: Sultan 2017년 9월 29일
Thanks John. I want to generate 1x15 dim array v =[v1,...,v15] such that v1+...+v15=1, vi\in [0,1], i=1,...15. The function randfixedsum(n,m,s,a,b) is showing error when I am running [x,v] = randfixedsum(1,15,1,0,1). Following is the error:
Index exceeds matrix dimensions.
Error in randfixedsum (line 95) x = (b-a)*x(p+repmat([0:n:n*(m-1)],n,1))+a; % Permute & rescale x

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Random Number Generation에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by