JavaやC++などで可能であることは知っていますが、Matlabでも可能ですか?最近、Matlabには、value++
代わりに使用する必要があるようなショートカットがないことを発見しvalue = value+1
たので、この関数を反復関数に変換できるかどうか疑問に思っています。どこから始めたらいいのかわからない。もしそうなら、それは再帰関数よりも有益ではありませんか?
function [lines] = recurse(R,C, lines, T_l, count, directions)
[rows, columns] = size(lines);
if((R < 2 || C < 2) || (R > rows-1 || C > columns - 1) || count>500)
count= count+1;
return;
end
count= count+1;
direction = directions(R,C);
if(direction >= 68 || direction <=-68)
if(lines(R-1,C) > T_l)
lines(R-1,C) = 0;
lines = recurse(R-1,C, lines, T_l, count, directions);
end
if(lines(R+1,C) > T_l)
lines(R+1,C) = 0;
lines = recurse(R+1,C, lines, T_l, count, directions);
end
elseif (direction <= -23 && direction >-68)
if(lines(R+1,C+1) > T_l)
lines(R+1,C+1) = 0;
lines = recurse(R+1,C+1, lines, T_l, count, directions);
end
if(lines(R-1,C-1) > T_l)
lines(R-1,C-1) = 0;
lines = recurse(R-1,C-1, lines, T_l, count, directions);
end
elseif (direction >= 23 && direction < 68)
if(lines(R+1,C-1) > T_l)
lines(R+1,C-1) = 0;
lines = recurse(R+1,C-1, lines, T_l, count, directions);
end
if(lines(R-1,C+1) > T_l)
lines(R-1,C+1) = 0;
lines = recurse(R-1,C+1, lines, T_l, count, directions);
end
else
if(lines(R,C+1) > T_l)
lines(R,C+1) = 0;
lines = recurse(R,C+1, lines, T_l, count, directions);
end
if(lines(R,C-1) > T_l)
lines(R,C-1) = 0;
lines = recurse(R,C-1, lines, T_l, count, directions);
end
end
lines(R,C) = 255;
return;
基本的に、私は現在、この2番目の関数を再帰的に呼び出す関数を持っています。この再帰関数を、コマンドの反復セットとして呼び出す関数に統合したいと思っていました。遅くなると確信していますが、速度は私にとって問題ではなく、ループがどのように機能するかを確認したいと思います。ありがとう。