Refresh random sample within a FOR loop

A have a data se of 1000 normally distributed values representing annual discount rate (dr). I wrote a code that randomly picks 20 values from the data set and assigns it to a formula that calculates net present value (npv) using those 20 values. What I want it to do is to run the simulation n-times and save the value of npv in a vector npvsim after each simulation. Numper of simulations is defined by u=length(npvsim), in this case 5.
What I get in results at the moment is the same value stored five times. It seems to me that i=randsample(dr,20) takes a sample once and the same values are then used for 5 times. Is there any way I can make these 20 values to be refreshed for each iterations? I'm kind of stuck and the existing answers provite little help.
Thank you in advance.
npvsim = zeros(5,1);
for u = length(npvsim) ;
%selecting 20 random discount rates for each year
i = randsample(dr,20);
for n = reshape(1:20,20,1);
npv = -2000+ sum(571.5./((1+i).^n));
npvsim(:,u') = npv;
end;
end;

 Accepted Answer

More Answers (0)

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Products

Release

R2021a

Community Treasure Hunt

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

Start Hunting!