我遇到的问题是我试图将 fireShot() 命令的结果与结果“Splash”进行比较。接下来我需要计算总的真实值(或每次 fireShot()= 'Splash')。但是,每次我尝试使用 while 循环或 if 循环时,我都会得到一个常数(与相应的随机数或我在各自绘图上的前面的函数不匹配)。我确信它的格式不是很讨人喜欢并且可以使用工作,但我相信我真正的问题在于 strcmp() 的值的统计。
无论如何,这是我的代码:
function [ output_args ] = fireShots(shotstofire, fieldSize, pondRadius)
%// This function will fire multiple shots and count how many of them
%// land in the pond.
%// Counts down total number of shots and subtracts 1 until
%// total is equal to '0'
while shotstofire > 0
shotstofire;
shotstofire = shotstofire - 1;
%// Calls fireShot function
Splash = fireShot(fieldSize,pondRadius);
Land = strcmp(Splash,'Splash');
end
%// If the ball hits inside the pond
%// Land (total tally) gets +1
if (Land)
Land = Land + 1;
else
end
end
我知道我的代码可能已关闭,但我的所有功能都可以按预期工作。