how to only plot a certain area of an existing plot
6 views (last 30 days)
Show older comments
Hi, so i have this figure which is produced from my code (attached). I would like to reproduce the plot but for it to be masked within a circle and for the data points to only be plotted within this circle. The circle is to have a radius of 0.045m and the centre is to be located at (0,0). I have also attached an image of what kind of thing I am after.
Thank you in advance! I have attached my code.
n = 250; % number of points on the voronoi diagram
L2x = zeros(1,n); % array to store the L2 x values
L2y = zeros(1,n); % array to store the L2 y values
for i=1:n
q = randi([-50 50],1,1); %Parameters for the random case
L2x(i) = q.*1e-3 ; %limit that L2 must be greater than 0.5mm is obeyed
w = randi([-50 50],1,1);
L2y(i) = w.*1e-3;
P = [L2x(:) L2y(:)]; %extracting the x and y values and placing it into one matrix
end
figure
voronoi(P(:,1),P(:,2)) % Plotting the voronoi diagram
[V,C] = voronoin(P); % storing the voroni vertexs' in V
V(isinf(V)) = 1; % replacing the inf values in the array to 1
for i=1:length(C) %finding the centroids for each cell
Cnew = V(C{i},:);
[xnew,ynew] = centroid(polyshape(Cnew(:,1),Cnew(:,2)));
% m = (x)
hold on
plot(xnew,ynew,'r+')
axis ([-0.050 0.050 -0.050 0.050])
hold off
end
0 Comments
Answers (1)
See Also
Categories
Find more on Voronoi Diagram in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!