필터 지우기
필터 지우기

Info

이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.

Difficulties programming coordinates identification

조회 수: 1 (최근 30일)
Alex castilla
Alex castilla 2018년 4월 13일
마감: MATLAB Answer Bot 2021년 8월 20일
I have two matrices:
1- contains the ‘x’ and ‘y’ coordinates ( 2816x2) for a trajectory walk.
2- the second one (9x3) contains the ‘index’,‘X’ and ’Y’ for the coordinates for nine tiles.
During the trajectory, a person walks on certain tiles. I would like to know how to identify the tile or tiles the person walks on using the index of the tiles (figure 1). Is it possible to obtain a column with 0’s and the tile’s indices?
For instances, if the person walks without passing through/on a tile is noted 0 and if the person walks on a tile the index of the tile 1. My goal is to add a column to the first matrix with the new data (like this 2816x3).

답변 (1개)

dpb
dpb 2018년 4월 13일
편집: dpb 2018년 4월 13일
[isHit,whereHit]=ismember(Tile(:,2:3),Traj,'rows');
isHit is T if the tile was touched during the walk; whereHit is the location in the (first) trajectory vector the intersection was. If there can be multiple crossings and need those, will need to do that lookup separately.
ADDENDUM The above assumes trajectory and tiles are discrete coordinates...does the tile cover some number of units of size of dX/dY in the tractory? If so, need neighborhood calc, not just coordinate match.
Let us know more if the above first assumption is erroneous.
  댓글 수: 1
Alex castilla
Alex castilla 2018년 4월 14일
Yes, you are right, I did a neighbourhood calculation to know if the subject walk on the tile(s). I added a width and height. this is the code:
w=30;% target position's width
h=30;% target position's height
reach_target=zeros(size(x));
for i= 1:length(x)
for e=1:length(X)
if (x(i)>(X(e)-w/2) & x(i)<(X(e)+w/2));
if(y(i)>(Y(e)-h/2) & y(i)<(Y(e)+h/2));
reach_target(i)=1;
end
end
end
end

이 질문은 마감되었습니다.

Community Treasure Hunt

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

Start Hunting!

Translated by