Filling missing points in a grid

조회 수: 8 (최근 30일)
fatoma Saml
fatoma Saml 2021년 5월 2일
편집: fatoma Saml 2021년 8월 16일
Hi everyone
I am wondering if anyone can help to mark the missing points on the grid with (x) . I have a regular points in x,y that I get from executing the differences between a predeifined points to get the grid, at the same time, some points are missing and I want to mark them (x red) as shown in the figure (i.e, (7,8), and the other missing points. How to select specific range of points with their index as marked in the black sqaure .
I have execute the code
M=3; N=4;
mN=[0:M-1]*N;
nM=[0:N-1]*M;
[xx yy]=meshgrid(mN, mN);
[x y]=meshgrid(nM, nM);
L1=[xx(:),yy(:)];
L2=[x(:),y(:)];
LL=[0,0];
L1= union(L1, L2, 'rows');
S=union(L1,LL,'rows');
figure
plot(S(:, 1),S(:,2) ,'o','color', 'b', 'markersize',4, 'linewidt',1);
LEN_S = size(S, 1);
MAX_x = max(S(:, 1));
MIN_x = min(S(:, 1));
MAX_y = max(S(:, 2));
MIN_y = min(S(:, 2));
[mx_mat, my_mat] = ndgrid(-(MAX_x - MIN_x):(MAX_x - MIN_x), -(MAX_y - MIN_y):(MAX_y - MIN_y));
mx_vec = mx_mat(:); my_vec = my_mat(:);
w = zeros(size(mx_vec));
n1 = cell(size(mx_vec));
n2 = cell(size(mx_vec));
for ii = 1 : size(S, 1)
for jj = 1 : size(S, 1)
index = (mx_vec == S(ii, 1) - S(jj, 1) & my_vec == S(ii, 2) - S(jj, 2));
w( index ) = w( index ) + 1;
n1{ index } = [n1{ index }; S(ii, :)];
n2{ index } = [n2{ index }; S(jj, :)];
end
end
D = [mx_vec, my_vec];
LEN_S = size(S, 1);
SS = repmat(S, [LEN_S, 1]);
SS_= kron(S, ones(LEN_S, 1));
[D1, ~, ind_SS] = unique(SS - SS_, 'rows', 'sorted');
fh2= figure (2);
plot(D1(:,1), D1(:,2) ,'square','color', 'r', 'markersize',5, 'linewidt',2);hold on
plot(D1(:,1), D1(:,2) ,'square','color', 'b', 'markersize',5, 'linewidt',2);hold on
axis([-inf inf -inf inf ]);
I apperciate any help
Thanks

채택된 답변

Doddy Kastanya
Doddy Kastanya 2021년 5월 5일
You could try to add the following at the end of your code:
hold on
text(7,8,'X','color','r')
If there are other points, then you could embed this in a for loop identifying the appropriate x and y position.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Subplots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by