Info
Cette question est clôturée. Rouvrir pour modifier ou répondre.
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 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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
0 commentaires
Réponses (1)
Geoff Hayes
le 10 Mai 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 commentaires
Geoff Hayes
le 11 Mai 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.
Cette question est clôturée.
Voir également
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!