Ältere Kommentare anzeigen
if I have a list of numbers and I want to know where a number lies between two numbers in that list.
2 Kommentare
Roger Stafford
am 19 Dez. 2016
Please give more details in your question! Better still, give a concrete example of the "list" and precisely what results you wish to obtain from it.
khamiis E
am 19 Dez. 2016
Akzeptierte Antwort
Weitere Antworten (2)
Walter Roberson
am 19 Dez. 2016
Suppose you have a vector of values in sorted order, and have some other values, and you want to know where in the vector the other values would sit. Then:
[~, ~, binnumber] = histcounts(TheOtherValues, TheVectorOfFixedValues);
Then, TheOtherValues(K) is between TheVectorOfFixedValues(binnumber(K)) and the next value.
5 Kommentare
Star Strider
am 19 Dez. 2016
The previous histcounts function was called histc with a slightly different calling and output syntax.
Walter Roberson
am 19 Dez. 2016
[~, binnumber] = histc(TheOtherValues, TheVectorOfFixedValues);
Walter Roberson
am 19 Dez. 2016
Note: this code was written assuming that your ranges had no gaps, but it appears from your diagram that it does not apply.
khamiis E
am 20 Dez. 2016
Andrei Bobrov
am 19 Dez. 2016
Bearbeitet: Andrei Bobrov
am 19 Dez. 2016
A = [10 25
30 45
50 150
300 450
500 501
502 600
630 700
720 800
801 815
820 1000]; % your "start-end"
B = [33 300 501 75 754 809 1000 47]'; % Let B - your numbers
b = prod(A - reshape(B,1,1,[]),2);
out = sum(bsxfun(@times,squeeze(b < 0 | b == 0),(1:size(A,1))'))
1 Kommentar
khamiis E
am 20 Dez. 2016
Kategorien
Mehr zu Variables finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
