for loop and indexing a matrix help
14 views (last 30 days)
Show older comments
Trying to make a function that if i input a matrix(x) and its conditions(cond), (x,cond)- it will resutun the index(row numders) that meet the conditions, as a vector. Any good examples of how this can be executed. Or if matlab has any helpful docs that can help?
0 Comments
Answers (1)
KSSV
on 23 Apr 2020
A = rand(5) ;
idx = A>0.7 ; % indices greater than 0.7
find(idx)
A(idx)
idx = A<0.5 ; % indices less than 0.5
find(idx)
A(idx)
idx = A>0.3 & A<0.7 ; % indices greater than 0.3 and less than 0.7
find(idx)
A(idx)
See Also
Categories
Find more on Matrices and Arrays in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!