Grouping or categorizing data based on conditions
5 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Dear all,
In my calculations data is generated as attached which is x,y,z and a value as 4th dimension.
I wanted to divide this data into goups based on their value for x,y and z and assign one index to each category and finally find how many points I have in each group. It's a kind of dividing a region into voxels for 3d or pixels in 2d.
For example, if 20 < x < 19 & 20 < y< 19 & 20 <z<19 => set 1 index for the data which are located in this category.
I found these functions but don't know which one is approporiate for my purpose as the data is huge; findgroups,categories(A) ,[X,Y,Z] = meshgrid(x,y,z), Y = discretize(X,edges).
Thank you in advance.
data = readtable ('Outpu.txt');
data = table2array(data);
x=data(:,1);
y=data(:,2);
z=data(:,3);
t=data(:,4);
figure
scatter3(x,y,z,2,t,'filled')
ax = gca;
ax.XDir = 'reverse';
zlim([-200 200])
xlim([-100 100])
ylim([-100 100])
view(-31,14)
xlabel('X')
ylabel('Y')
zlabel('Z')
cb = colorbar;
clim([0 20])
grid minor
Réponse acceptée
Plus de réponses (1)
KSSV
le 27 Juil 2022
How about this?
data = readtable ('https://in.mathworks.com/matlabcentral/answers/uploaded_files/1078835/Outpu.txt');
data = table2array(data);
x=data(:,1);
y=data(:,2);
z=data(:,3);
t=data(:,4);
x0 = linspace(-40,40,5) ;
y0 = linspace(-40,40,5) ;
z0 = linspace(-200,200,10) ;
G = NaN(length(x),1) ;
count = 0;
for i = 1:length(x0)-1
for j = 1:length(y0)-1
for k = 1:length(z0)-1
count = count+1 ;
idx = ((x0(i)<= x) & (x < x0(i+1))) & ((y0(j)<= y) & (y < y0(j+1))) & ((z0(k)<= z) & (z < z0(k+1))) ;
G(idx) = count ;
end
end
end
%% Remove the points
x(isnan(G)) = [];
y(isnan(G)) = [];
z(isnan(G)) = [];
G(isnan(G)) = [] ;
figure
scatter3(x,y,z,2,G,'filled')
colormap(turbo)
5 commentaires
KSSV
le 28 Juil 2022
You can get the count from G also. nnz(G==1) gives the number of points in the first cube etc.
Voir également
Catégories
En savoir plus sur Computational Geometry dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!