How to find a value among a huge dataset?
1 回表示 (過去 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
0 件のコメント
採用された回答
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 件のコメント
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Characters and Strings についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!