此问题已关闭。 请重新打开它进行编辑或回答。

I have error in the following code, the error is (Error in Example_random (line 3) if Initialization ), could you help me to fix the problem. Thank you.

1 次查看(过去 30 天)
function [Command,Exp]=Example_random(Exp,Initialization)
if Initialization
Exp.Workspace= [0 0; 0 10; 10 10; 10 0];
Exp.Animation.Title='[Random movements]';
Exp.Initial_pose=[1 3 0; 9 7 pi]';
V(1).Vertex=[ 5 2; 4 3; 6 4; 5 3];
V(2).Vertex=[ 4 5; 3 7; 2 8; 1 6; 2 5];
V(3).Vertex=[ 6 6; 7 7; 8 6];
V(4).Vertex=[10 0; 10 10];
V(5).Vertex=[ 0 0; 0 10];
V(6).Vertex=[ 0 10; 10 10];
V(7).Vertex=[ 0 0; 10 0];
for i=1:Exp.Robots
Command=[]; return
for i=1:Exp.Robots
if Exp.Agent(i).Sensor(1).Presence
Command(:,i)=[-0.2; 0];
elseif (Exp.Iteration>1)&&(Exp.History.Command(Exp.Iteration-1,1,i))<0,
Command(:,i)=[0; pi/2+rand(1)*pi];
Command(:,i)=[0.2; 0];

回答(1 个)

Geoff Hayes
Geoff Hayes 2018-5-10
Ameer - you haven't posted the error message so it is will be hard to guess what the problem is. Since line 3 is
if Initialization
the error message could be
>> Example_random
Error using Example_random (line 3)
Not enough input arguments.
because you are calling the function Example_random and not passing in any input parameters. If this is the case, then you would need to pass in values for the input parameters of Exp and Initialization. Exp seems to be a struct of some kind and Initialization is a boolean (at least according to your code).
>> [Command,Exp] = Example_random([], true);
Presumably if the second input parameter is false, then you would be passing in a struct that has already been initialized.
  6 个评论
Ameer Hamza
Ameer Hamza 2018-5-11
When i deleted this [Command,Exp] = Example_random([], true) the code give this error: >> Example_random Not enough input arguments.
Error in Example_random (line 2) if Initialization In comment they solve it by [Command,Exp] = Example_random([], true) but after adding it, the code not working it has error.
Geoff Hayes
Geoff Hayes 2018-5-11
Ameer - you have to call this function from the command line (or from some other file). For example, at the command line you would do
>> [Command,Exp] = Example_random([], true)
And this will call your Example_random function and pass in the correct parameters.


Community Treasure Hunt

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

Start Hunting!

Translated by