0

How to generate a vector of lets say 5 decimal values such that their sum is 10.

for i=1:5
   d(i)=rand;
end

1)I know this generates the vector, but how to include the condition? 2) can I generate negative numbers as well?

Amira Akra
  • 163
  • 11

1 Answers1

0
 d = rand(5,1);
 d = d * 10 / sum(d);
user1543042
  • 3,422
  • 1
  • 17
  • 31