fastFindK

Find k occurances of a value in array. Slightly faster than the usual routs.

You are now following this Submission

Example :
>> a = [ 1 4 5 4 4 7 4 4 9 4 ];
>> find(a==4,5)

ans =

2 4 5 7 8

>> fastFindK(4,a,5)

ans =

2
4
5
7
8

I had a situation in which I was looking for indices many many times. Unfortunately, I could not get around the problem via logical arrays or anything of that sort (there was quite a bit of code which I would have to change otherwise). So I did what any rational programmer would do, that is I wasted a good few precious minuets and one or two unnecessary keystrokes to write this lame code.

I recommend just using logical arrays .....

Cite As

Christopher Harris (2026). fastFindK (https://www.mathworks.com/matlabcentral/fileexchange/49162-fastfindk), MATLAB Central File Exchange. Retrieved .

General Information

MATLAB Release Compatibility

  • Compatible with any release

Platform Compatibility

  • Windows
  • macOS
  • Linux
Version Published Release Notes Action
1.0.0.0