Search code examples
matlabmaxscilababsolute-value

Scilab - How to get the maximum absolute value in a Matrix with its original sign?


I am using Scilab 5.5.2

I am trying to get the maximum absolute value in a vector.

See this example

a = [-9;-19;11]

If I type:

max(abs(a))

I get:

19

That's close to what I want. Yes, 19 is the maximum absolute value. However, I would like to have the maximum absolute value in its original form, in this case, as -19.

How can I solve this? Is there a command in Scilab especially designed for that?

I tried looking at documentation but couldn't find.


Solution

  • You can find where the maximum happens and then get the value there:

    [word, idx]=max(abs(a));
    maximum=a(idx);