how do I find the element number of the minimum value of a 1d array

Viewed 25

I know how to find the minimum value of an array using the min function, but I'm unsure of how to locate the element number using a function

function [m,r]= RightMin(a1)
% m gives the minimum value in the 1d array given
m=min(a1);
% linearindices is supposed to name the element number of the minimum value found.
linearindices = find(a1==m) ;
r=linearindices;
end 

so if the array was a=[4,7,67,9,34,1,6,87,5,34] then m=1 but r should be 6 r=6 because the minimum number 1 is in the sixth elemental position in the array.

1 Answers

You can request the index from the min() function.

Example:

[m, r] = min(a1);
Related