~ in Matlab function
이 질문을 팔로우합니다.
- 팔로우하는 게시물 피드에서 업데이트를 확인할 수 있습니다.
- 정보 수신 기본 설정에 따라 이메일을 받을 수 있습니다.
오류 발생
페이지가 변경되었기 때문에 동작을 완료할 수 없습니다. 업데이트된 상태를 보려면 페이지를 다시 불러오십시오.
이전 댓글 표시
0 개 추천
I have some Matlab function call as
[Hz,~] = freqz(num, den, f, fsA)
What "~" means or what does it represent?
채택된 답변
0 개 추천
It is a placeholder for the optional second argument but indicates to not assign to a variable -- in the above call, there is no reason to use it; it is the same as if had written
Hz = freqz(num, den, f, fsA);
the second output (and any/all subsequent) will just go to the bit bucket.
There would be reason to use it, and its raison d'etre would be if the expression were instead
[~,w] = freqz(num, den, f, fsA);
there it is the placeholder for the frequency response first output variable but for some reason that wasn't needed; only the second output, the angular frequency values were required. It saves creating unwanted/unneeded variable(s) in the workspace.
BTW -- This is a badly-named return variable in the original code; the first return argument from freqz is the response magnitude; 'Hz' implies a frequency; the third output variable is, in fact, the frequency vector in hertz.
PS. I know the syntax is in the doc somewhere, but one can't search for the single character punctuation and it isn't mentioned at all in the basics of function creation...so I never came across where that is.
댓글 수: 6
Steven Lord
2022년 10월 18일
Related to the PS: searching for ~ in the online documentation lists the documentation page for the not, ~ function/operator as the first hit. The Tips section of that page states that you can also use ~ as a placeholder and links to a page that discusses ignoring inputs in function definitions.
It should probably also link to the Ignore Function Outputs page that's a Related Topic for the Ignore Inputs in Function Definitions page; I'll note that to the documentation staff.
Walter Roberson
2022년 10월 18일
편집: Walter Roberson
2022년 10월 18일
https://www.mathworks.com/help/matlab/matlab_prog/ignore-function-outputs.html
also mentioned in the tips for https://www.mathworks.com/help/matlab/ref/not.html and in the description of tilde in https://www.mathworks.com/help/matlab/matlab_prog/matlab-operators-and-special-characters.html#bvg3oy_-5
dpb
2022년 10월 18일
"searching for ~ in the online documentation..."
But the @doc link in Answers doesn't bring up anything is where one is in the forum...it's a lot more effort to have to go delve into the main doc and search there just to add a little to an answer when/if pressed for time.
Walter Roberson
2022년 10월 18일
Note that there are some functions where it makes a difference whether you output to a single output or if you specify an output list with ~ as the trailing outputs. For example
A = rand(5,7,4);
b = size(A); %b is 5 7 4
[b, ~] = size(A); %b is 5
[b, c] = size(A); %b is 5 c is 28
[b, c, ~] = size(A); %5 and 7
[b, c, d] = size(A); %5, 7, and 4
Also: it is not possible for a function to detect that ~ has been used. Functions can only detect the number of output positions.
Walter Roberson
2022년 10월 19일
the @doc facility misses a number of things. For example you cannot even reference toolboxes by name.
dpb
2022년 10월 19일
It also often lists many toolbox overloaded functions before the base product.
It's annoying it only works if click on with the mouse, typing more than the @ sign goes to name match and then tab won't/doesn't select the matched but have to go click on it, too...but it's still better than having to go open the full doc directly, just could be better...
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Logical에 대해 자세히 알아보기
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!웹사이트 선택
번역된 콘텐츠를 보고 지역별 이벤트와 혜택을 살펴보려면 웹사이트를 선택하십시오. 현재 계신 지역에 따라 다음 웹사이트를 권장합니다:
또한 다음 목록에서 웹사이트를 선택하실 수도 있습니다.
사이트 성능 최적화 방법
최고의 사이트 성능을 위해 중국 사이트(중국어 또는 영어)를 선택하십시오. 현재 계신 지역에서는 다른 국가의 MathWorks 사이트 방문이 최적화되지 않았습니다.
미주
- América Latina (Español)
- Canada (English)
- United States (English)
유럽
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
