Storing repeated values from a loop

I am unsure how to store the values, then take the average, from my output St into a large matrix so that I can work with the numbers more easily. I have looked through other responses, and cant seem to find a solution. The code is as follows. Any help is greatly appreciated.

1 个评论

@Quinn Hayward: we cannot run a screenshot, we cannot edit a screenshot, we cannot search a screenshot, we cannot use a screenshot. Screenshots as basically useless as a way of giving us your code. If you want help then please delete the screenshot and give your code as text.

请先登录,再进行评论。

 采纳的回答

Please, never post your code as an image. It actively discourages people to help, because we can't copy and paste code to fix it. The code below should be something like what you mean.
Pay attention to the m-lint warnings. They alert you to potential bugs and possible places to improve your code. Use functions to keep your workspace clean (or at least consider using clearvars instead), and don't use clc if you're not planning on using disp or fprintf.
mu=0.004;
sigma=0.05;
S1=72;
N=261;
K=5;
dt=sigma/sqrt(N);
M=zeros(N,K);
for k=1:K
St=zeros(N,1);St(1)=S1;
for i=2:N
epsilon=randn;%don't overwrite the internal eps function
St(i)=St(i-1)+St(i-1)*(mu*dt+sigma*epsilon*sqrt(dt));
end
M(:,k)=St;
end
plot(M)
xlim([1 N])
xlabel('days')
ylabel('value')

更多回答(0 个)

类别

帮助中心File Exchange 中查找有关 Loops and Conditional Statements 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by