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.
Info
This question is closed. Reopen it to edit or answer.
Show older comments
function [Command,Exp]=Example_random(Exp,Initialization)
if Initialization
Exp.Robots=2;
Exp.Workspace= [0 0; 0 10; 10 10; 10 0];
Exp.Animation.Title='[Random movements]';
Exp.Initial_pose=[1 3 0; 9 7 pi]';
Exp.Animation.Grid=0;
Exp.Addons={'Map'};
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];
Exp.Map.Obstacle=V;
for i=1:Exp.Robots
Exp=Add_sensor(Exp,i,'ProximitySensor');
Exp.Agent(i).Sensor(1).Range=0.3;
end
Command=[]; return
end
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];
else
Command(:,i)=[0.2; 0];
end
end
Answers (1)
Geoff Hayes
on 10 May 2018
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 Comments
Ameer Hamza
on 11 May 2018
Edited: Walter Roberson
on 11 May 2018
Walter Roberson
on 11 May 2018
Your code appears to be calling itself as the first thing it does.
It would help if you posted a copy of the error message.
Ameer Hamza
on 11 May 2018
Edited: Walter Roberson
on 11 May 2018
Walter Roberson
on 11 May 2018
Is there a message about recursion level being exceeded? Because your code is calling itself. You are defining a function Example_random and the first thing the function does is call Example_random, which is the function itself. The line
[Command,Exp] = Example_random([], true)
should be in some other file.
Ameer Hamza
on 11 May 2018
Geoff Hayes
on 11 May 2018
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.
This question is closed.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!