![](/profiles/wavemetrics/themes/wavemetrics/logo.png)
Grouping points in XY data into user-defined bins for retrieving statistics
![](/sites/default/files/styles/thumbnail/public/m.rogers/profile-images/2023-01/DSC02716.jpg?itok=IQGiXOFi)
Hello,
I was wondering if there was an equivalent in Igor for the discretize() function in MATLAB. I've attached a description of this function here. This function returns the indices of the bins that contain the elements of X.
For example, if I had a wave X [1,3,3,5,7] and edges [2,4,6,8], the function would return [NaN,1,1,2,3]. Having this function would enable me to retrieve a wave of indices that I can use to select points in other waves of the same size as X so I can calculate statistics (e.g., mean, stdev, number of points) etc.
For the time being, I have been copying and pasting waves from Igor into MATLAB to use this function and then copying them back into Igor, which has been time-consuming.
Thank you for your time.
Here's an attempt to write discretize as a user function:
I assume edges to be monotonic.
The way I did it is probably wildly inefficient. Probably someone will be able to improve upon this.
January 17, 2023 at 02:28 am - Permalink
Here is an arguably better way to do it with a user function:
January 17, 2023 at 08:11 am - Permalink
it's more efficient to use a built-in function:
January 17, 2023 at 08:34 am - Permalink
Thank you for your work and thoughts Tony! I had not used FindLevel before, this works very well in the user-defined functions you made.
January 17, 2023 at 10:53 am - Permalink