Identify location of the 2D grid data

조회 수: 2 (최근 30일)
Pete sherer
Pete sherer 2024년 11월 9일
댓글: Pete sherer 2024년 11월 9일
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

채택된 답변

Bruno Luong
Bruno Luong 2024년 11월 9일
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

추가 답변 (1개)

Shashi Kiran
Shashi Kiran 2024년 11월 9일
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.

카테고리

Help CenterFile Exchange에서 Develop Apps Using App Designer에 대해 자세히 알아보기

태그

제품


릴리스

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by