# Binning 3D data und reasign Bin properties to data

4 ビュー (過去 30 日間)
Marc Laub 2022 年 12 月 8 日

Hey, following problem
I have following problem: I have 3D data from which I need to calculate properties.
To reduce the calculation time I want to bin the data, and then only calculate the properties of the bin-voxel that are populated and then reasign the calculated voxel properties to the data points that are within that specific bin.
Right now my sollution looks like this:
a5pre=compositions(:,1);
a7pre=compositions(:,2);
a8pre=compositions(:,3);
%% BINNING
a5pre_edges=[0,linspace(0.005,0.995,19),1];
a5pre_val=(a5pre_edges(1:end-1) + a5pre_edges(2:end))/2;
a5pre_val(1)=0;
a5pre_val(end)=1;
a7pre_edges=[0,linspace(0.005,0.995,49),1];
a7pre_val=(a7pre_edges(1:end-1) + a7pre_edges(2:end))/2;
a7pre_val(1)=0;
a7pre_val(end)=1;
a8pre_edges=a7pre_edges;
a8pre_val=a7pre_val;
[~,~,bin1]=histcounts(a5pre,a5pre_edges);
[~,~,bin2]=histcounts(a7pre,a7pre_edges);
[~,~,bin3]=histcounts(a8pre,a8pre_edges);
bins=[bin1,bin2,bin3];
[A,~,C]=unique(bins,'rows','stable');
a5pre=a5pre_val(A(:,1));
a7pre=a7pre_val(A(:,2));
a8pre=a8pre_val(A(:,3));
It works, but I am not sure if its the smartes way to do it. I also wrote it as a mex function with the coder, because i thought that functions like histcount and unique would be faste that way because I think those are the time critical functions, but it actually took twice as long...
I know of one more restriction:
initial data 0.9<composition(:,2) + composition(:,3) <1
But I am not sure how to include this in the histcount functions, because this would reduce the number of bins in which data points can be in and so make it faster.
Anybody has an idea how to improve it, or is this the way to go? Length of Compositions can be 200 but could also be 40k
EDIT: From the "Run and Time" function i know that a huge portion of that time is spend in the unique2012a function.
Best regards

サインインしてコメントする。

### カテゴリ

Find more on Data Distribution Plots in Help Center and File Exchange

R2022b

### Community Treasure Hunt

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

Start Hunting!