how to only plot a certain area of an existing plot
조회 수: 5 (최근 30일)
이전 댓글 표시
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
답변 (1개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Voronoi Diagram에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!