## how to find the location of a specific array element within the specific range in matlab?

### pavan sunder (view profile)

on 20 Dec 2016
Latest activity Edited by José-Luis

### José-Luis (view profile)

on 21 Dec 2016
for example: d=[1 2 3 4 8 10 4 5 6 12 10 13];
i want to find the location of 10 within the range [4 8]
the expected answer would be 6.
I used the following command: a=find(d(4:8)==10);
Plz suggest me a way to solve this.

### Tags

No tags entered yet.

### José-Luis (view profile)

on 20 Dec 2016
Edited by José-Luis

### José-Luis (view profile)

on 21 Dec 2016

EDITED to avoid the use of range
d=[1 2 3 4 8 10 4 5 6 12 10 13];
idx(numel(d)) = 0;
idx(4:8) = 1;
a = find(d == 10 & idx)

Image Analyst

### Image Analyst (view profile)

on 20 Dec 2016
If you have the stats toolbox, you might want to rename since range is a built-in function of that toolbox.
José-Luis

### José-Luis (view profile)

on 21 Dec 2016
Thanks, good point. While range should have rung a bell, there are so many reserved names that I wonder if this is headed towards the atrocity that dunders are.

### Image Analyst (view profile)

on 20 Dec 2016

Here's a way:
d=[1 2 3 4 8 10 4 5 6 12 10 13];
startingIndex = 4;
endingIndex = 8;
valueToLookFor = 10;
locations = find(d(startingIndex : endingIndex) == valueToLookFor) + startingIndex - 1