Ignore output arguments (R2006a)

Some versions of MATLAB allow to ignore selected output arguments by using '~'. How can I do that in R2006a (v7.2)?
For example: [Y,I]=sort(X) --> [~,I]=sort(X); I just want the second output
Thanks in advance

 채택된 답변

Oleg Komarov
Oleg Komarov 2012년 4월 3일

5 개 추천

You cannot.
This feature was introduced in R2009b: Ignore Selected Arguments on Function Calls
What you can do is:
  1. [I,I] = sort(X)
  2. [trash,I] = sort(X)
In the first case, you'll keep only one variable in the workspace, but it's not very elegant (in my opinion). In the second case, it's immediate that you need only the second output.

댓글 수: 2

Jan
Jan 2012년 4월 3일
The [I,I] method forces me to think twice when I read the code, while the [trash, I] is trivial. An option is to add "clear('trash')" to release the occupied memory.
Sandra
Sandra 2012년 4월 3일
Thanks Oleg and Jan for your answers.

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Argument Definitions에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by