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.
man abs
tells you why you got that result: abs -- integer absolute value functionYou want
fabs
here: "floating-point absolute value function". Note that you need to includemath.h
(abs
is usually instdlib.h
).