私が抱えている問題は、fireShot() コマンドの結果を結果の「スプラッシュ」と比較しようとしていることです。次に、真の値の合計 (または毎回 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
コードがオフになっている可能性があることはわかっていますが、この関数までのすべての関数は想定どおりに機能します。