how can I locate a number in a vector with out using the function find?
조회 수: 1 (최근 30일)
이전 댓글 표시
I am trying to locate a number in vector with out using the function 'find'.is there a way i could do this?
댓글 수: 2
채택된 답변
Stephen23
2017년 2월 9일
Here is one easy way using indexing:
>> x = 5 % value to find
>> V = randi(9,1,10) % vector of values
V =
3 5 6 7 6 3 5 2 6 6
>> idx = 1:numel(V);
>> idx(V==x)
ans =
2 7
댓글 수: 2
Stephen23
2017년 2월 11일
@Stephanie Velasco: if my answer helped you, please consider accepting it. This is an easy way for you to show your appreciation (we are all volunteers).
추가 답변 (1개)
Image Analyst
2017년 2월 9일
편집: Image Analyst
2017년 2월 9일
You can use ismember(), ismembertol(), intersect(), or strfind(), or even an "if" inside a for loop.
댓글 수: 2
Jan
2017년 2월 9일
@IA: The source code of ismember, ismembertol and inetrsect could contain a call to the find() function. The question sounds as a homework problem, so I'd prefer the for loop and an if, although this is a really bad solution from the viewpoint of software engineering.
참고 항목
카테고리
Help Center 및 File Exchange에서 Matrix Indexing에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!