필터 지우기
필터 지우기

Question on function variables i.e. ~

조회 수: 4 (최근 30일)
Seetha Rama Raju Sanapala
Seetha Rama Raju Sanapala 2015년 12월 17일
편집: Walter Roberson 2015년 12월 17일
[~,I] = max(abs(xc));
This is code taken from an example in MATLAB. I read somewhere that ~ can be used to indicate 'don't care' variables - variables that are not required in further program.
I could have used some variable name, say a, instead of ~, and ignore a. What is the advantage if you use ~. Is it saving space by not storing the data not required?

답변 (1개)

James Tursa
James Tursa 2015년 12월 17일
편집: James Tursa 2015년 12월 17일
It is mainly to avoid cluttering your workspace with variables you don't need in a "neat" manner. E.g.,
[~,I] = max(abs(xc));
does the same thing as:
[M,I] = max(abs(xc));
clear M
In both cases, the first output argument is still calculated and returned by the function. Using ~ simply saves you, the programmer, the trouble of clearing unwanted variables manually (MATLAB will do it for you in the background).
  댓글 수: 2
Seetha Rama Raju Sanapala
Seetha Rama Raju Sanapala 2015년 12월 17일
@James Tursa, if I understood you correctly, it will create some variable (unknown to us) for the output but will immediately clear it and it is not accessible any more. Thanks for the clarification. Has it been documented anywhere in MATLAB? I just want to know how to look for such information! Thanks again!

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

카테고리

Help CenterFile Exchange에서 Get Started with MATLAB에 대해 자세히 알아보기

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by