MATLAB: I want plot y = 1-exp(-x) for 3000 times(repeat 3000 times). The value x is the random number from [0,1]. Please use “rand”to get x and use “cdfplot” to get the y

plot exponential curve by random numbersplot exponential graph by random numbers

I want plot y = 1-exp(-x) for 3000 times(repeat 3000 times). The value x is the random number from [0,1]. Please use "rand"to get x and use "cdfplot" to get the y

Best Answer

Some general hints:
  1. The rand function produces a double array, not a cell array. You therefore don't need curly braces to select 1 element.
  2. If you know before-hand how many iterations your loop will have, it is generally easier to use a for-loop.
  3. If you compute something inside a loop, don't forget to use indexing to store the result in an element of an array instead of in an entire variable.
These should help you improve your code and get it to work.