MATLAB: Calculate weight of each 2D data point weight a data set consists of x and y, if I want to find out the associated weights for each point. What can I do? Best Answer Please expand on your question.Are you trying to find out how many of the points fall in to each square of a grid? If so, then you can use accumarray for that:xgrid = 1 + floor(Nx * (x - min(x)) ./ (max(x) - min(x)));ygrid = 1 + floor(Ny * (y - min(y)) ./ (max(y) - min(y)));weights = accumarray([xgrid(:), ygrid(:)], 1);This will produce an Nx by Ny grid of counts. Related SolutionsMATLAB: Regridding 2D-grid shuffled points from 1-D arrays A single SORTROWS command will undo the shufflexyz_grid = sortrows([x(:) y(:) z(:)],[1 2]);ny = find(diff(xyz_grid(:,1)),1,'first'); % ==length(unique(y))nx = numel(x)/ny; % ==length(unique(x))xyz_grid = reshape(xyz_grid,[ny,nx,3]);x_grid = xyz_grid(:,:,1);y_grid = xyz_grid(:,:,2);z_grid = xyz_grid(:,:,3); MATLAB: Visualizing Dense Areas in cartesian plane xpnts = 100; %set as desiredypnts = 100; %set as desiredminx = min(x);miny = min(y);scalex = xpnts ./ (max(x) - minx);scaley = ypnts ./ (max(y) - miny);scaledx = 1 + floor(x-minx) * scalex;scaledy = 1 + floor(y-miny) * scaley;densemap = accumarray([scaledx(:),scaledy(:)],1);imagesc(densemap);You might also find this File Exchange contribution to be useful. Related QuestionData picking from gridSmoothen 3d surf plotAutomatically fit grid spacingSub2ind errorPlotting streamlines in 3D from a non-rectangular grid
Best Answer