Identify location of the 2D grid data

4 vues (au cours des 30 derniers jours)
Pete sherer
Pete sherer le 9 Nov 2024
Commenté : Pete sherer le 9 Nov 2024
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

Réponse acceptée

Bruno Luong
Bruno Luong le 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))
locOri = 5x4 logical array
1 1 0 0 1 1 1 0 1 0 1 0 0 0 0 0 1 1 0 1

Plus de réponses (1)

Shashi Kiran
Shashi Kiran le 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)
1 1 0 0 1 1 1 0 1 0 1 0 0 0 0 0 1 1 0 1
This output has 1s at positions that correspond to the points in rectList and 0s elsewhere, as expected.
Hope this helps.

Catégories

En savoir plus sur Logical dans Help Center et File Exchange

Tags

Produits


Version

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by