| Date | File | Comment by | Comment | Rating |
|---|---|---|---|---|
| 10 Nov 2008 | fastsearch Search an element in the array, or the next smaller and greater | Franworth, Dru | I tried the following code in Matlab clear all x=randn(10000,1); tic
This is the output:
-----------------------------------------------------------------------------------
|
|
| 10 Nov 2008 | fastsearch Search an element in the array, or the next smaller and greater | Franworth, Dru | There is a slight bug in your code. In line 134 , you should have
Instead, you have fastsearch(array,von,m1-1,wert,bias); Same thing for line 136. Basically, all you have to do is replace fastsearch in lines 134 and 136 with fastsearch_indeed. |
|
| 09 Nov 2008 | fastsearch Search an element in the array, or the next smaller and greater | Franworth, Dru | I tried the following code and got an error message. As you can see, the number I am searching for is inside the sorted vector but it is generating an error message. ----------------------------------------------------------------------------------- >> x=randn(10000,1);
Error in ==> fastsearch>fastsearch_indeed at 137
Error in ==> fastsearch at 59
>> z z = 0.4291 >> min(y) ans = -3.5758 >> max(y) ans = 4.0050 >> find(abs(y-z)==min(abs(y-z))) ans = 6694 |
|
| 06 May 2008 | fastsearch Search an element in the array, or the next smaller and greater | Kuklin, Valentin | Hi Alexander, thanks for your notes. I think there is no bug. This code with "Check if wert is inside of array." is used only for the first run, for example if you have array=1:1:100 and you search -5 or 105. For the further runs it does not play any role, the searched number will be anyway within [von, bis]. Actually it can not be infinite recursion because every "if" ends with "return" but not with the new call of function. But anyway I am happy that someone uses my function and tries to find bugs :) Thanks again :) Valentin Kuklin |
|
| 05 May 2008 | fastsearch Search an element in the array, or the next smaller and greater | Chemeris, Alexander | It's good that such a useful algorithm in finally implemented in Matlab :)
if wert<array(von)
That is "von" and "bis" are used instead of "1" and "end". Without this fix algorthm may enter infinite recursion in certain cases. |
|
| 19 Oct 2007 | fastsearch Search an element in the array, or the next smaller and greater | (us) schwarz, urs | sorry, this was not copy/pasted properly at the end of the code example: -or- if you feel that ISSORTED eats too much time, simplify it to function ix=fastsearch(a,v,b)
which comes with no additional cost... us |
|
| 19 Oct 2007 | fastsearch Search an element in the array, or the next smaller and greater | (us) schwarz, urs | a very nice utility; a user-friendly improvement could look like this
% eg,
just a thought
|
|
| 18 Oct 2007 | fastsearch Search an element in the array, or the next smaller and greater | Cao, Yi | Excellent. Compare with
It is more than 100 times faster than these normal ways to get similar answers in matlab. The weak point is that the array has to be sorted first. It will take more than 2 seconds to sort a array of size about 10^7. However, it could be useful for cases where repeated searches are required. One more thing, I guess using the golden ratio might be even more efficient. |
|
NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Terms prior to use.
Contact us at files@mathworks.com