MATLAB Answers

0

How to look for minimum value in a vector from backwards?

Asked by George Ansari on 23 Aug 2017
Latest activity Edited by José-Luis
on 23 Aug 2017
Suppose I have a vector A = [5 6 4 1 1 1]; I'd like to find the index of a minimum value. If I try min function in a regular way:
[A_min index] = min(A)
it would give me somethin like:
A_min = 1
index = 4
But the result that I'm trying to get should be:
A_min = 1
index = 6
How do I search for a minimum value starting from the end of the vector without flipping it?
George.

  0 Comments

Sign in to comment.

Products

2 Answers

Answer by José-Luis
on 23 Aug 2017
Edited by José-Luis
on 23 Aug 2017
 Accepted Answer

A = [5 6 4 1 1 1];
A_min = min(A);
idx = find(A == A_min,1,'last')
Also
[A_min,idx] = min(fliplr(A));
idx = numel(A) - idx + 1

  0 Comments

Sign in to comment.


Answer by KL
on 23 Aug 2017

find(A==A_min,1,'last')

  0 Comments

Sign in to comment.