フィルターのクリア

why is my nested if statement not working?

1 回表示 (過去 30 日間)
Josh Williams
Josh Williams 2020 年 3 月 15 日
コメント済み: Josh Williams 2020 年 3 月 15 日
n=27
while n>1
n=n-1;
shiptext= [22 6;38 21;24 36;2 30;6 2;15 31;22 15;24 15;10 33;29 11;32 15;29 21;31 4;25 27;29 27;10 11;35 17;15 14;22 20;21 29;23 22;3 22;33 9;8 38;10 4;11 29];
shipnumber= size(shiptext,1);
disp(shipnumber);
plot(shiptext(:,1),shiptext(:,2),'.')
idr1=randi(26,1,1);
row1=shiptext(idr1,:);
idr2=randi(26,1,1);
row2=shiptext(idr2,:);
a=row2-row1;
xdistance=a(1);
ydistance=a(2);
distance=sqrt(((xdistance)^2)+((ydistance)^2))
disp(distance)
if
distance<0.5
disp('warning')
end
end

採用された回答

Sriram Tadavarty
Sriram Tadavarty 2020 年 3 月 15 日
Hi Josh,
The condition for the if statement must be placed side rather than in next line.
Update the code of if statement with this:
if distance<0.5 % the condition should be inline with the 'if'
disp('warning');
end
This should solve.
Regards,
Sriram
end
  1 件のコメント
Josh Williams
Josh Williams 2020 年 3 月 15 日
cheers for all the help, still learing at this point

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeAssembly についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by