Finding the indexes of multiple elements that are equal to a certain value in an array

W=400;Lb=5;Lc=3;
% a)
D = (1:0.01:2.9);
T = Lb*Lc*W./(D.*sqrt(Lc^2-D.^2));
[t,d]=min(T);
Specifically, I need help finding the D values where T increases 10 percent above its minimum value. My initial approach was to try and find the indexes of the elements in D that are equal to 1466.67, which is 10 percent above the function's minimum value, then plug them into D to find out what values those indexes correspond to. I've searching on here, and have tried using the find() command and the ismembertol() command, to no avail. I am probably using them wrong anyways, and would greatly appreciate any help in solving my problem.

 Accepted Answer

D(find(T>=t*1.1,1))

3 Comments

mask = T>=t*1.1;
starts = strfind([false, mask], [0 1]);
stops = strfind([mask, false], [1 0]);
Now starts(K) is the index of the beginning of a region where T > 1.1 times min(T), and stops(K) is the index of the end of the region. You can use these as indices into D to get corresponding D values
>> starts
starts =
1 154
>> stops
stops =
63 191
So T(1) through T(63) are all above 1.1 * min(T), as are T(154) through T(191)
You could also say that T(64) is the first location it is less than 1.1*min(T) and that T(153) is the last location it is less than 1.1*min(T) .
It depends on how you phrase your question. If the data starts above the threshold has it already increased above the threshold, or does it not increase above the threshold until some point after the first line you see a data point that is less than the threshold? If the data ends above the threshold, then does the end of data mark a point at which it stops being above the threshold, or does it not stop being above the threshold unless there is at least one further point that is below the threshold ?
The data begins above the threshold, dips beneath it for a bit, then comes back above the threshold and ends above it.
Also, thank you very much for your help. A little bit of tweaking with the code you suggested, and I can now use it to get a decent answer. Thanks!

Sign in to comment.

More Answers (2)

This just returns "1"

1 Comment

You will not find any place where they are exactly equal. Do you need to find all that are above the threshold, or all below, or do you need to find the transition boundaries?

Sign in to comment.

The transition boundaries, I think. Which is why that ismembertol() looked promising, but I don't think I used it right.

Products

Community Treasure Hunt

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

Start Hunting!