How can I delete unwanted grid cells from 'particle plot' which do not have any particle?
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
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
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/155071/image.jpeg)
0 Commenti
Risposte (1)
Image Analyst
il 16 Feb 2016
If you have it, why not simply use hist3() to construct a 2D histogram of the data?
Vedere anche
Categorie
Scopri di più su Data Distribution Plots in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!