how to find the location of a specific array element within the specific range in matlab?
1 次查看(过去 30 天)
显示 更早的评论
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);
the answer i am getting is 3 instead of 6.
Plz suggest me a way to solve this.
0 个评论
回答(2 个)
José-Luis
2016-12-20
编辑:José-Luis
2016-12-21
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)
2 个评论
Image Analyst
2016-12-20
If you have the stats toolbox, you might want to rename since range is a built-in function of that toolbox.
Image Analyst
2016-12-20
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
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!