How to find a value among a huge dataset?

2 次查看(过去 30 天)
Hey guys,
I've got a problem with how to find a value among a series of data in a situation that our value does not necessarily exist in the main dataset. e.g: we have a data array:
data = [1;2;3;4;5;6;7;8;9;10];
and we want to know where is the place for A = 4.365
Of course here it is between data(4,1) and data(5,1) but how can I ask my program to do it in a tremendously huge array? I mean I can do it with loops but is there any special command for that?
Thank you very much :)
Mehdi

采纳的回答

Walter Roberson
Walter Roberson 2011-9-30
Provided that data is strictly increasing:
[junk, binnum] = histc(A, [-inf data inf]);
The binnum returned will be an index K such that A goes strictly before the K'th value -- so if A exactly matches the K'th value, K+1 would be returned. If length(data) + 1 is returned, then the A value either exactly matches or exceeds the last data value.
Feel free to subtract 1 from the result if that makes things easier: that would mean that a returned value of 0 means that the data precedes the first data value.
A can be a vector of values.
Note that, as per usual, if your data values are non-integral, you need to consider round-off errors: a value that is algebraically (say) 4, might numerically get calculated as 4*(1-eps) or even smaller.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Characters and Strings 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by