Return function in a recursive function code

1 回表示 (過去 30 日間)
Rdmn Raja
Rdmn Raja 2018 年 4 月 25 日
コメント済み: Rdmn Raja 2018 年 4 月 27 日
When I create a recursive code and have the desired output, after following it with 'return' the next line - it continues running and outputting unwanted results - can someone help me avoid this please.
  17 件のコメント
Ameer Hamza
Ameer Hamza 2018 年 4 月 26 日
From the code you gave, all calls to HELP function are followed by end. There are no statements after that. How can the function start editing matrices? Or are there any other statements which you haven't included in the given code?
One possible solution can be adding a return after every call to HELP. For example
if isempty(P)==1
HELP(A,[],1:length(A),[],i+1,1,0,[],C);
return;
else
HELP(A,R,P,X,i,j+1,n-1,D,C);
return;
end
Similar for other two calls to HELP.
Rdmn Raja
Rdmn Raja 2018 年 4 月 27 日
thanks, added it in but didn't check in the debugger mode if it runs after as I get the desired output I need.

サインインしてコメントする。

回答 (0 件)

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by