How to sort 3D data into bins?

조회 수: 7 (최근 30일)
wkm42
wkm42 2016년 7월 4일
댓글: Ramesh Venkatasubramanian 2020년 10월 27일
Hey,
I'm looking for some function like 'gridfunc' in the example beneath.
Datapoints:
x: torque = [12,13,20,30]
y: speed = [512,800,1300,1506]
z: z = [2,2,1,4]
Intervalls of my desired grid:
torque_intervall = [10,20,30]
speed_intervall = [500,1000,1500,2000]
The function im looking for:
output = gridfunc(torque,speed,z,torque_intervall,speed_intervall)
output(torque=10..20,speed=500..1000)= [z(1),z(2)]
Thanks for any suggestions!

채택된 답변

Walter Roberson
Walter Roberson 2016년 7월 5일
For each variable, histc() and take the second output, or histcounts() and take the third output. This will be the bin number along that dimension. Now you can use
output = accumarray([firstbinnum(:), secondbinnum(:), thirdbinnum(:)], z(:), [], @(vals) {vals}, {});
The result will be a 3D cell array where the first dimension reflects the bin numbers along the first variable, the second dimension reflects the bin numbers along the second variable, the third dimension reflects the bin number along the third variable. Each element of the cell array will be a cell array of z values that fell into the combination of the three bins; this might be empty if nothing happened to fall into that voxel.
  댓글 수: 2
wkm42
wkm42 2016년 7월 5일
Thanks! Thats exactly what i was looking for :)
Ramesh Venkatasubramanian
Ramesh Venkatasubramanian 2020년 10월 27일
Can you explain your code with the above example?

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Thorsten
Thorsten 2016년 7월 4일
Try hist3.
  댓글 수: 3
Star Strider
Star Strider 2016년 7월 4일
It’s going to be very difficult to create any sort of meaningful interpolation surface from your data:
torque = [12,13,20,30];
speed = [512,800,1300,1506];
z = [2,2,1,4];
figure(1)
stem3(torque, speed, z)
grid on
axis square
view([-60, 30])
xlabel('Torque')
ylabel('Speed')
zlabel('Z')
wkm42
wkm42 2016년 7월 5일
Well its just an example and not the actual data..

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Shifting and Sorting Matrices에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by