フィルターのクリア

Two functions in the same file causing error: "Maximum recursion limit of 500 reached"

1 回表示 (過去 30 日間)
Giorgos Papakonstantinou
Giorgos Papakonstantinou 2013 年 5 月 22 日
I have the following function file.
function y=myfun(x)
y=2*x;
if any(y<0)
positive(x);
y=myfun(x);
end
end
function x=positive(x)
y=myfun(x);
idx=find(y<0);
x(idx,1)=-x(idx,1);
% y=myfun(x);
end
I want to give a matrix for example x=[-2;2]; and calculate y=2*x; If the any of y is negative i would like to change the x such that y is always positive.
The problem is mostly due to control flow but I cannot solve it. Can you help me?

回答 (1 件)

Iain
Iain 2013 年 5 月 22 日
The simplest answer is to set: y = 2 * abs(x);
If you do that, you don't need to recursively call the function.

カテゴリ

Help Center および File ExchangeGeometric Transformation and Image Registration についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by