How can I delete unwanted grid cells from 'particle plot' which do not have any particle?

3 visualizaciones (últimos 30 días)
Hi,
I have some data points which is basically associated with the particle position in terms of x and y coordinates. e.g. Each particle has unique x and y coordinates. You can see this in the attached figure.
My purpose is to place the nxn size grid over this particle distribution plot. In this way, each grid cell will have certain no of particles inside it. My purpose is to count the no. of particles falling in each grid cell. Based on this data, I want to count standard deviation of it.
From this particular MATALB forum http://www.mathworks.com/matlabcentral/answers/129646-collate-data-in-grid, I could be able to do this task.
The code is as follow:
r = -0.0008 ;
R = 0.0528;
format long;
filename = 'perf_8.xlsx';
xlrange ='A9:B4659';
T = xlsread(filename,xlrange);
x = (T(:,1));
y = (T(:,2));
n = numel(x);
v1 = randi( 1, n, 1 ) ; % A series of data associated with points.
% - Build grid.
nBinsX = 20 ;
nBinsY = 20 ;
xg = linspace( r, R, nBinsX+1 ) ;
yg = linspace( r, R, nBinsY+1 ) ;
nCells = nBinsX * nBinsY ;
% - Build figure.
figure(1) ; clf ; hold on ;
set( gcf, 'Color', 'w', 'Units', 'Normalized', ...
'Position', [0.1,0.5,0.3,0.3] ) ;
% - Plot grid.
plot( [xg;xg], repmat( [r;R], 1, numel( xg )), 'Color', 0.8*[1,1,1] ) ;
plot( repmat( [r;R], 1, numel( yg )), [yg;yg], 'Color', 0.8*[1,1,1] ) ;
axis([-0.02 0.06 -0.02 0.06]);
% - Build set of unique IDs for cells.
xId = sum( bsxfun( @ge, x, xg(1:end-1) ), 2 ) ;
yId = sum( bsxfun( @ge, y, yg(1:end-1) ), 2 ) ;
cellId = nBinsY * (xId - 1) + yId ;
% - Plot cell IDs.
labels = arrayfun( @(k)sprintf( '%d', k ), 1:nCells, 'UniformOutput', false ) ;
[X,Y] = meshgrid( (xg(1:end-1)+xg(2:end))/2, (yg(1:end-1)+yg(2:end))/2 ) ;
text( X(:), Y(:), labels, 'Color', 'b', 'FontSize', 5 ) ;
% - Plot data points with labels.
plot( x, y, 'r.', 'LineWidth', 2, 'MarkerSize', 8 ) ;
labels = arrayfun( @(k)sprintf( 'P%d\\in%d | %d,%d', k, cellId(k), ...
v1(k) ), 1:n, 'UniformOutput', false ) ;
% - Compute some stat (sum, mean) per block on v1 and v2.
blockSum_v1 = accumarray( cellId, v1, [nCells, 1] ) ;
fprintf( '\nBlock sum v1 =\n' ) ;
disp( blockSum_v1 ) ;
z=numel(blockSum_v1)
n
s=std(blockSum_v1,1)
m=mean(blockSum_v1)
cov=s/m
Now my concern is, there are so many grid cells outside the particle position graph(on all four corner, you can see the empty cells) which do not have particles inside them. The smaller the grid size is I choose, obviously more no. such grid cells will be there on every corner (which are outside of particle distribution graph and they won't have any particles).
I do not want to count these grid cells while calculating 'standard deviation' and 'mean'. (Consider it like I can delete these data points manually in excel and then calculate the standard deviation and mean. But it won't be feasible to manually for large no. of cells).
Can anyone suggest me some modification in the code so that, "blockSum_v1" itself won't count these grid cells ( and which are outside the particle graph and have no points). In this way, while calculating Standard deviation and 'mean', these grid cells won't be there.
Or is there any other way to delete this grid cells?
Any suggestion will be highly appreciated. Thank you in advance.
Regards, Sud

Respuestas (1)

Image Analyst
Image Analyst el 16 de Feb. de 2016
If you have it, why not simply use hist3() to construct a 2D histogram of the data?
  1 comentario
Sudhanshu Soman
Sudhanshu Soman el 23 de Feb. de 2016
Can you please tell me more about it?
Like I tried histogram and hist3() both. It is not helpful for me. As with this option I can omit the empty cells which have no particle counts but this also includes the empty cells which are inside the circle. I just want to omit the outer circles.
Here is the modification done in last part of code.
figure(2) ; clf ; hold on ;
nbins=max(blockSum_v1);
h=histogram(blockSum_v1,'BinLimits',[1,nbins+1],'BinWidth',1);
counts=(h.Values)
t=[1:(nbins)]
Parts=(t.*counts)
s=std(Parts,1)
m=mean(Parts,1)
cov=s/m
Also, am thinking of another way out.
Q-Instead of rectangular grid, is it possible to place the circular grid on it ? As you can the grid is rectangular and due to which some grid cells are falling outside the circle. These cells have no data points. If I can place the circular grid then these empty cells won't be there ( that's what I want).
Is it possible to do that? Thank you so much in advance.

Iniciar sesión para comentar.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by