Not enough input arguments.

1 回表示 (過去 30 日間)
rafael
rafael 2014 年 10 月 23 日
コメント済み: Star Strider 2014 年 10 月 23 日
Hello, I am trying to run the program, but apper the error:
Error using rwn (line 8) Not enough input arguments.
code:
% random walk on a square lattice
% input the number of jumps nt
% output is the square displacement rs2 and the list of positions x and y
function[rs2,x,y]= rwn(nt)
x(1)=0; % start particle at the origin
y(1)=0;
rs2(1)=0;
Fd=ceil(4.*rand(nt,1));% list with nt entries, each a random integer from 1 to 4, LINE 8
delx = [1 0 -1 0]; % these two lines define the jumps on the square lattice
dely = [0 1 0 -1]; % right, up, left, down
for j=1:nt % sum over nt jumps
x(j+1)=x(j)+delx(Fd(j)); % x position at j+1 jump
y(j+1)=y(j)+dely(Fd(j)); % y position at j+1 jump
rs2(j+1)=x(j+1)^2 + y(j+1)^2; % square displacement position at j+1 jump
end

回答 (1 件)

Star Strider
Star Strider 2014 年 10 月 23 日
It ran without problems for me with this call:
nt = 25;
[rs2,x,y]= rwn(nt)
The only suggestion I have is that you could change the ‘Fd’ line to:
Fd=randi(4,nt,1);
  2 件のコメント
rafael
rafael 2014 年 10 月 23 日
I am new at matlab, I tryed to run but the follow error apper:
Function definitions are not permitted in this context.
Star Strider
Star Strider 2014 年 10 月 23 日
You cannot define a function of the type you are using in a regular MATLAB script. You have to create a separate .m file for it. Save your function as rwn.m and it should work without problems.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by