~ in Matlab function

11 vues (au cours des 30 derniers jours)
Peter Balazovic
Peter Balazovic le 18 Oct 2022
Commenté : dpb le 19 Oct 2022
I have some Matlab function call as
[Hz,~] = freqz(num, den, f, fsA)
What "~" means or what does it represent?

Réponse acceptée

dpb
dpb le 18 Oct 2022
Modifié(e) : dpb le 18 Oct 2022
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 commentaires
Walter Roberson
Walter Roberson le 19 Oct 2022
the @doc facility misses a number of things. For example you cannot even reference toolboxes by name.
dpb
dpb le 19 Oct 2022
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...

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Function Creation dans Help Center et File Exchange

Produits


Version

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by