Info

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

If else statement problem

1 回表示 (過去 30 日間)
aleea razali
aleea razali 2020 年 5 月 20 日
閉鎖済み: MATLAB Answer Bot 2021 年 8 月 20 日
Hi, i trying to generate new value of location in range 2 until 30. However, i notice that the value of location generated are not in the range. And it seem like while loop also not working perfectly as the value of ca and ma after run is zero. Could anybody please help with this? or could someone tell me the mistake that i had done? Thank you
function [Location]=Construct3(Variable2)
ca=0; pa=0.25; ma=0;
while ca<=50
SG=size(Variable2,1);
FC=rand(size(Variable2))>pa;
stepsize1=rand*(Variable2(randperm(SG),:)-Variable2(randperm(SG),:));
pink=Variable2+stepsize1.*FC;
Location=round(pink);
if Location<2 & Location>30,
ca=ca+1
else ma=ma+1
end
if ma==20,
break
end
end

回答 (1 件)

Rik
Rik 2020 年 5 月 20 日
ca is already smaller than 50 at the start of the loop, so the content of the while loop doesn't run.
You could find this out on your own by setting a break point at the start of the function and stepping through your code line by line.

この質問は閉じられています。

Community Treasure Hunt

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

Start Hunting!

Translated by