Info

この質問は閉じられています。 編集または回答するには再度開いてください。

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 日間)
Ameer Hamza
Ameer Hamza 2018 年 5 月 10 日
閉鎖済み: MATLAB Answer Bot 2021 年 8 月 20 日
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

回答 (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