Problem 645. Getting the indices from a vector
This is a basic MATLAB operation. It is for instructional purposes.
---
You may already know how to find the logical indices of the elements of a vector that meet your criteria.
This exercise is for finding the index of indices that meet your criteria. The difference is this:
vec = [11 22 33 44];
thresh = 25;
vi = (vec > thresh)
vi =
0 0 1 1
What we are looking for now is how to get the values
x =
3 4
Because those are the indices where the binary comparison is true.
Given a vector, vec, return the indices where vec is greater than scalar, thresh.
Solution Stats
Problem Comments
-
5 Comments
Show
2 older comments
goc3
on 18 Nov 2016
I added six more test cases.
Nguyen Huu Hung
on 14 Sep 2019
hay
Kerem Kutan
on 12 Jun 2020
kinda easy
Miriam Sánchez Fernández
on 7 Nov 2020
It's easy with function "find"
Benjamin Hoehne
on 1 Dec 2020
use "find"
Solution Comments
Show commentsProblem Recent Solvers11710
Suggested Problems
-
Project Euler: Problem 3, Largest prime factor
1784 Solvers
-
Back to basics 12 - Input Arguments
619 Solvers
-
"Low : High - Low : High - Turn around " -- Create a subindices vector
579 Solvers
-
We love vectorized solutions. Problem 1 : remove the row average.
883 Solvers
-
Height of a right-angled triangle
2010 Solvers
More from this Author51
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!