Clear Filters
Clear Filters

Resample the output file of a simulation

2 views (last 30 days)
Spinjex on 14 Apr 2020
Answered: Ayush Gupta on 3 Jun 2020
I have a matrix containing two columns as output of my simulation. In the first column I have the position, and in the second one my variable. I used a high resolution in my simulation, but I would like to bin the results. I scored my variable every 1 millimeter in x, but I want to plot it every 1 cm to have a smoother curve, summing 10 voxels at the time. How do I do that? Is there a simple variable to bin the data summing every 10 entries? Can I sum in a non uniform way too (first 5, and then every 10, then the last 5 voxels)? At the moment I am using a simple plot (x, v) function. Thank you!

Answers (1)

Ayush Gupta
Ayush Gupta on 3 Jun 2020
The following procedure might help you, where X is the second column of the matrix which needs to be binned:
bins = [start_position of x (in mm): 10: end_position of x (in mm)+1]
Y = discretize(X,bins) will give which value belongs to which bin
To get number of values in a bin following can be used:
[Y,E] = discretize(X,bins,diff(bins))
Where Y will give each bin’s count and E will give the bins
The above procedure can be followed for uniform bins but for non-uniform bins, it can defined as -
bins = [start_position of x (in mm), start_position of x (in mm) + 5 (in mm) :10: end_position of x (in mm) - 4(in mm) , end_position of x (in mm)+1] .
For further help you can leverage the documentation of discrete function.


Find more on Graph and Network Algorithms in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!