Matlab should introduce functions like ‘’abs2‘’

8 vues (au cours des 30 derniers jours)
min lee
min lee le 10 Déc 2023
Commenté : John D'Errico le 10 Déc 2023
Now matlab has only the function 'abs'.
In many case, I need not abs but abs2.
The function abs2 is a inbuilt function in julia as far as I know. It is very convenient.
  2 commentaires
Dyuman Joshi
Dyuman Joshi le 10 Déc 2023
I don't see a point in doing that, when it is just abs(x).^2 or x.^2 (for real numbers).
If you do, you can write to The MathWorks explaining why they should be doing that as well - Contact Support > Create Service Request > Technical Support > Product help, bugs, suggestions or documentation errors.
Meanwhile, you can define and save a function named abs2() yourself and use it like it is built-in function -
abs2(-3)
ans = 9
abs2(2.5)
ans = 6.2500
function y = abs2(x)
y = abs(x).^2;
end
John D'Errico
John D'Errico le 10 Déc 2023
The beauty of any language, MATLAB included, is you can write such a function for your own use. Put it in your personal library of functions. Now you have extended MATLAB to work the way you want it to work. @Dyuman Joshi has already given you the code, in what should probably have been an answer. (I would STRONGLY recommend adding comments and help of course. But the code is there.
Yes, you can also put in a feature request directly to MathWorks. If abs2 is the greatest thing since sliced bread, then tell them! Don't bother telling us, as that does nothing.

Connectez-vous pour commenter.

Réponses (0)

Catégories

En savoir plus sur Waveform Design and Signal Synthesis dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by