Standard Deviation from a certain point

5 ビュー (過去 30 日間)
confused
confused 2015 年 10 月 28 日
編集済み: Thorsten 2015 年 10 月 28 日
I have written a program where i am running a program to reach an equilibrium but i not want to find the std from the first point were it reaches N/2 till the end of the program i know i need to set up an index but i am not getting much luck on how to go about it can anyone help
N=34 %total number of particles
n=N % amount on left hand side
TIME = 200; % setting up array for time
NUMBER = zeros (200, 1); % setting up array for number
NUMBER (1) = n; % causing the plot to start at n or 4
for i = 2:TIME;
if n/N > rand(1) ; % if n/N is less than the random number generated take one from the left
n = n-1;
else n = n+1; % otherwise add one to the left
end
NUMBER(i) = n;
end
  2 件のコメント
Image Analyst
Image Analyst 2015 年 10 月 28 日
time is a built in function. You do not assign anything to it. Also, you never even initialized the badly-named time or n.
confused
confused 2015 年 10 月 28 日
編集済み: confused 2015 年 10 月 28 日
sorry i left out two first line in the program! i just edited it also i have taken out the time in my program it was left there from previous workings on the program.

サインインしてコメントする。

採用された回答

Thorsten
Thorsten 2015 年 10 月 28 日
編集済み: Thorsten 2015 年 10 月 28 日
Your program is fine. After the loop, you just have to compute
i1 = find(NUMBER == floor(N/2), 1, 'first');
std(NUMBER(i1:end))
This is easier than trying to find i1 within the loop. If you like to do it in the loop, use
i1 = NaN;
for ...
if ~isnan(i1) && n == floor(N/2)
i1 = i;
end

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by