MATLAB save output as array
this is my code so far, I'm going to need to save these as arrays or vectors i think to take some statistics on them.
how do i save each walkers position relitive to time
I should end up with 1000x 1000 matrix i think
or 1000 arrays
walkers=1000;
%walkers=input('how many walkers do you want to simulate?')
N = 1000;
%N = input('how many steps do you want?')
for k= 1:walkers
displacement= randn(1,N);
x = cumsum(displacement);
plot(x);
ylabel('position');
xlabel('time');
title('Position of walker');
end
i was trying something to the effect of:
for k= 1:walkers
displacement= randn(1,N);
x(k) = cumsum(displacement);
plot(x(k));
ylabel('position');
xlabel('time');
title('Position of walker');
end
but couldnt get it to function correctly
i also need to put a limit to the min and max the "walkers" can go.
Code :
MATLAB Code:
%walkers=1000;
walkers=input('how many walkers do you want to simulate? :')
%N = 100;
N = input('how many steps do you want? :')
for k= 1:walkers
displacement(k,1:N)= randn(1,N);
x(k,1:N) = cumsum(displacement(k,1:N));
plot(x(k,1:N));
hold on;
ylabel('position');
xlabel('time');
title('Position of walker');
end
OUTPUT:
>> walkers_prog
how many walkers do you want to simulate? :1000
walkers =
1000
how many steps do you want? :1000
N =
1000
Get Answers For Free
Most questions answered within 1 hours.