Hi
I have of course read the explanations regarding the return statement. Still in the following case:
if (parameter < 1)
disp('Wrong parameters...');
return
end
I don't see what difference it makes if we use "return" here or we dispense with it..
Thanks

댓글 수: 1

Just a suggestion - instead of disp() you might use
uiwait(warnglg('Wrong parameters...'));
I think it's a little nicer to have a popup message box. Better yet, use sprintf() to create your string and tell your users what they entered and what the valid range is.

댓글을 달려면 로그인하십시오.

 채택된 답변

Walter Roberson
Walter Roberson 2013년 1월 25일

0 개 추천

If you do not "return" then the rest of the function would be executed.

댓글 수: 3

Neha
Neha 2017년 3월 7일
Maybe this is off topic but I could not find the solution anywhere else. What is the equivalent command in R for "return"? I am new to programming so please do not mind if this is a very basic question. Thanks in advance! :)
Guillaume
Guillaume 2017년 3월 7일
You'll be better off asking a forum dedicated to R!
return(g)
This tells me that R has return() and that typically you would need to tell it what to return.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Evgeny Pr
Evgeny Pr 2013년 1월 25일
편집: Evgeny Pr 2013년 1월 25일

1 개 추천

You need to use ERROR function, do not return:
function myfunc(parameter)
if (parameter < 1)
error('Wrong parameters...');
end
% continue
end
...or:
function myfunc(parameter)
if (parameter < 1)
disp('Wrong parameters...');
else
% continue
end
end

카테고리

태그

질문:

2013년 1월 25일

댓글:

2017년 3월 7일

Community Treasure Hunt

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

Start Hunting!

Translated by