%% Initial Conditions
N = 2500; % How many total steps per walk
M = [ 100, 1000, 2500, 10000, 25000, 100000, 1000000]; % How many Random Walks are being simulated(Helpful nest for next code)
x_t(1) = 0 ; % Starting Point for X-position
y_t(1) = 0 ; % Starting Point for Y-position
%% Loops and Calculations
for m = 1:M % Number of walks being calculated for in loop
for n = 1:N % Looping all values of N into x_t(n).
A = sign(randn) ; % Generates either +1 or -1 depending on the SIGN of RAND.
x_t(n+1) = x_t(n) + A ; % Based on Factorial process to calculate next x-position
A = sign(randn); % Generates either +1 or -1 depending on the SIGN of RAND. y_t(n+1) = y_t(n) + A ; % Based on Factorial process to calculate next y-position
end plot(x_t, y_t) ; % Plots over time as the PERSON is WALKING
hold onend
MATLAB: I’m trying to set the first for loop (M) to run for the values I have but I can’t figure out how to get it run for the following values and not just the first.
for loopMATLABrandom walkrepeat loop for different values
Best Answer