close all;
hold on
%Edited
M = zeros(100,500);
%
for count = 0:99
x = [];
p = 0;
for i = 1:499
n = rand(1);
if n > 0.5
p = p+1;
end
if n < 0.5
p = p-1;
end
x(i) = p;
end
%Edited
for j = 1:500
M(n,j) = x(j);
end
%
X = abs(x);
Y = 1:length(X);
ps = csapi(X,Y);
fnplt(ps)
end
hold off
grid on
title('Random Walk Distances')
xlabel('Distance from the Origin')
ylabel('Each Iteration of the Experiment')
My intent is to find a mean curve of all the curves plotted by the code. To do so I'm thinking of finding the mean value for each index of the array's then plotting that curve, however, I'm only keeping the value of the last iteration how can I store all values in a large matrix.
Edit : I've surrounded the change I was thinking in (%) but it doesn't work. States :
Error in Random_walk_1D (line 30)
M(n,j) = x(n);
Subscript indices must either be real positive integers or logicals.
nis , e.g.0.3, thenM(0.3,j)is wrong, isn't it? Because well, subscript indices must ve either real positive integers or logicals.