Identify location of the 2D grid data
2 views (last 30 days)
Show older comments
Hi
I have this data and have transformed it into 2D [X, Y].
rectList = [...
1 1 1 1
1 2 1 1
1 3 1 1
1 5 1 1
2 1 1 1
2 2 1 1
2 5 1 1
3 2 1 1
3 3 1 1
4 5 1 1];
xRange = [ min( rectList(:,1)) max( rectList(:,1))];
yRange = [ min( rectList(:,2)) max( rectList(:,2))];
allX = xRange(1):deltaX:xRange(2);
allY = yRange(1):deltaY:yRange(2);
[X, Y] = meshgrid( allX, allY);
Is there to identify logical index of X,Y that belongs to original point, rectList. so it looks like
locOri =
[1 1 0 0
1 1 1 0
1 0 1 0
0 0 0 0
1 1 0 1]
Thanks much
0 Comments
Accepted Answer
Bruno Luong
on 9 Nov 2024
rectList = [...
1 1 1 1
1 2 1 1
1 3 1 1
1 5 1 1
2 1 1 1
2 2 1 1
2 5 1 1
3 2 1 1
3 3 1 1
4 5 1 1];
deltaX = 1;
deltaY = 1;
xRange = [ min( rectList(:,1)) max( rectList(:,1))];
yRange = [ min( rectList(:,2)) max( rectList(:,2))];
allX = xRange(1):deltaX:xRange(2);
allY = yRange(1):deltaY:yRange(2);
[X, Y] = meshgrid( allX, allY);
locOri = reshape(ismember([X(:),Y(:)],rectList(:,1:2),'rows'), size(X))
More Answers (1)
Shashi Kiran
on 9 Nov 2024
To identify the logical index of points in the X,Y grid that correspond to the original points in rectList, you can follow these steps:
- locOri is created as a logical matrix of the same size as X and Y, initially set to false.
% Initialize locOri as a logical array with zeros
locOri = false(size(X));
- For each point in rectList, find where X and Y match the current point’s coordinates in rectList. Then update locOri to true at those indices.
% Loop through each point in rectList and set corresponding locOri entries to true
for i = 1:size(rectList, 1)
% Find the indices in X and Y that match the current rectList point
xMatch = X == rectList(i,1);
yMatch = Y == rectList(i,2);
% Set locOri to true at positions matching both x and y
locOri = locOri | (xMatch & yMatch);
end
disp(locOri)
This output has 1s at positions that correspond to the points in rectList and 0s elsewhere, as expected.
Hope this helps.
0 Comments
See Also
Categories
Find more on Logical 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!