Create a histogram of y-axis positions at x=100?
1 回表示 (過去 30 日間)
古いコメントを表示
I'm simulating atomic jumps in a 1D lattice.
This code takes a series of 30 of a sequence of 100 random single integer atomic jumps and plots them on a single plot.
for i=1:30
n = 100;
P = zeros(n,1);
P(1) = 0; % Starting value
for i=2:n % i is the number of steps from 1 to 100
R = rand;
if R < 0.5
S = -1;
elseif R > 0.5
S = 1;
end
P(i) = S+P(i-1) % Gives the next random walk from the new position P every time
end
ylabel('Position')
xlabel('Jump Count')
title('Random Atomic Jumps in a 1-D Lattice')
plot(1:n,P)
hold on
end
Can you help provide the code to create a histogram of the 30 y-axis positions on this plot, at x=100?
0 件のコメント
回答 (1 件)
Mario Malic
2020 年 11 月 23 日
Hello,
I have changed a bit of your code so it doesn't overwrite the values within i loop.
n = 100;
P = zeros(i,n); % Array initialisation
for i=1:30
P(1) = 0; % Starting value
for j=2:n % i is the number of steps from 1 to 100
R = rand;
if R < 0.5
S = -1;
elseif R > 0.5
S = 1;
end
P(i,j) = S+P(i,j-1); % Gives the next random walk from the new position P every time
end
ylabel('Position')
xlabel('Jump Count')
title('Random Atomic Jumps in a 1-D Lattice')
end
plot(1:n, P);
histogram(P(:,end)); % Gets the last value of each series
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Histograms についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!