Let A = [1 2 4 6 10], I want to find the indices of the matrix for which the element less than 5.
So if I say: A < 5, then it will return [1 1 1 0 0]. How can I proceed to get the index of all those 1's?
Thanks

 채택된 답변

TastyPastry
TastyPastry 2015년 11월 9일

0 개 추천

idx = 1:numel(A);
mask = A < 5;
idx = idx(mask);

추가 답변 (1개)

Thorsten
Thorsten 2015년 11월 9일
편집: Thorsten 2015년 11월 9일

1 개 추천

To get numerical indices, use find
idx = find(A < 5);
You can also use logical indices, that are often faster:
idx = A < 5;
In both cases you get the indexed numbers using
A(idx)

카테고리

도움말 센터File Exchange에서 Matrices and Arrays에 대해 자세히 알아보기

태그

질문:

cgo
2015년 11월 9일

댓글:

cgo
2015년 11월 9일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by