How to code a 1D-random walk with wait time?
显示 更早的评论
Hi,
I'm trying to write a code for 1D-random walk with waiting time between jump of particle.
But, the code gives error.
If you kindly advice me the correction, it will help me immensely.
The code is as below with its error:
%Input value for Random walk
defaultValue = 250; %Total number of steps
titleBar = 'Enter the input value';
userPrompt = 'Enter the number of steps to take';
dlgtitle = 'Input';
causerInput = inputdlg(userPrompt,userPrompt,1,{num2str(defaultValue)});
if isempty(causerInput)
return
end
inputValue = round(str2num(cell2mat(causerInput)));
%Check for a valid input
if isnan(inputValue)
inputValue=defaultValue;
message = sprintf('Input value must be an integer. \nI will use %d and continue.', inputValue);
uiwait(warndlg(message));
end
%Turbulence intensity equation for Random Walk
numberofWalks = inputValue;
stepsperWalk = 250;
waitingTime = pause(120.0);
delta_X = rand(stepsperWalk);
delta_T = pause(rand);
xt = zeros(numberofWalks,2);
tic
for step = 2:numberofWalks
if toc < waitingTime
xt(step,1) = xt(step,1) + delta_X(step);
xt(step,2) = xt(step,2) + delta_T(step);
end
end
drift_vel = mean(xt(step,1)/xt(step,2));
diff_coeff = mean(xt(step,1)^2/(2*xt(step,2)));
ERROR:
Index exceeds the number of array elements. Index must not exceed 2.
Error in pde2fshear_v4Perturbed_bistable>pdex2pde (line 641)
xt(step,2) = xt(step,2) + delta_T(step);
With rgds,
rc
采纳的回答
更多回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!



