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
댓글 수: 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!