Resample the output file of a simulation

1 Ansicht (letzte 30 Tage)
Spinjex
Spinjex am 14 Apr. 2020
Beantwortet: Ayush Gupta am 3 Jun. 2020
Hello,
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!

Antworten (1)

Ayush Gupta
Ayush Gupta am 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.

Kategorien

Mehr zu Graph and Network Algorithms finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by