Resample the output file of a simulation

1 次查看(过去 30 天)
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!

回答(1 个)

Ayush Gupta
Ayush Gupta 2020-6-3
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.

类别

Help CenterFile Exchange 中查找有关 Surface and Mesh Plots 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by