Matlab should introduce functions like ‘’abs2‘’

9 次查看(过去 30 天)
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 个评论
Dyuman Joshi
Dyuman Joshi 2023-12-10
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 2023-12-10
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.

请先登录,再进行评论。

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Waveform Design and Signal Synthesis 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by