~ in Matlab function
現在この質問をフォロー中です
- フォローしているコンテンツ フィードに更新が表示されます。
- コミュニケーション基本設定に応じて電子メールを受け取ることができます。
エラーが発生しました
ページに変更が加えられたため、アクションを完了できません。ページを再度読み込み、更新された状態を確認してください。
古いコメントを表示
0 投票
I have some Matlab function call as
[Hz,~] = freqz(num, den, f, fsA)
What "~" means or what does it represent?
採用された回答
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!Web サイトの選択
Web サイトを選択すると、翻訳されたコンテンツにアクセスし、地域のイベントやサービスを確認できます。現在の位置情報に基づき、次のサイトの選択を推奨します:
また、以下のリストから Web サイトを選択することもできます。
最適なサイトパフォーマンスの取得方法
中国のサイト (中国語または英語) を選択することで、最適なサイトパフォーマンスが得られます。その他の国の 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)
