How to Code max(abs) in MATLAB

545 Views Asked by At

I have the following code in MATLAB which I am trying to rewrite in a mex file using C (or C++):

[a,b] = max(abs(C));

where C is a vector, a is the maximum absolute value of all the elements in vector C, and b is the index of a.

Please can anyone help me with the solution to this? I already tried to use "abs" function but it returned the positive integers (but I want them to remain double with their decimal values included). Many thanks in advance.

1

There are 1 best solutions below

0
On

man abs tells you why you got that result: abs -- integer absolute value function

You want fabs here: "floating-point absolute value function". Note that you need to include math.h (abs is usually in stdlib.h).