Binning 3D data und reasign Bin properties to data

조회 수: 2 (최근 30일)
Marc Laub
Marc Laub 2022년 12월 8일
답변: Shubham 2023년 9월 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

답변 (1개)

Shubham
Shubham 2023년 9월 8일
I understand that you want to reduce the calculation time. You are trying to bin the data to improve the efficiency.
You can improve the solution by using the restriction you mentioned:
initial data 0.9<composition(:,2) + composition(:,3) <1
The “a5pre’” and a7pre uses the 2nd and 3rd columns of the composition matrix, respectively. Therefore, you can reduce your bins that do not satisfy this condition.
For better understanding, kindly go through the following piece of code:
valid_bins = (0.9 < a7pre + a8pre) & (a7pre + a8pre < 1);
bins = [bin1(valid_bins), bin2(valid_bins), bin3(valid_bins)];
This would give you the bins that follow the restriction that you mentioned.
Hope this helps!!

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

제품


릴리스

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by