Matlab should introduce functions like ‘’abs2‘’

조회 수: 4 (최근 30일)
min lee
min lee 2023년 12월 10일
댓글: John D'Errico 2023년 12월 10일
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에서 Matrix Indexing에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by