Matlab should introduce functions like ‘’abs2‘’

8 visualizzazioni (ultimi 30 giorni)
min lee
min lee il 10 Dic 2023
Commentato: John D'Errico il 10 Dic 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 Commenti
Dyuman Joshi
Dyuman Joshi il 10 Dic 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 il 10 Dic 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.

Accedi per commentare.

Risposte (0)

Categorie

Scopri di più su Waveform Design and Signal Synthesis in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by