필터 지우기
필터 지우기

Find index for a coordinate pair in cell array

조회 수: 3 (최근 30일)
rbharrs
rbharrs 2021년 10월 29일
편집: Chris 2021년 10월 29일
I have a cell array size 99x2 (xStates). The first column are matrices with x,y pairs on the first and second columns respectively. The second cell array column has ID's for each of these coordinate pairs.
For each iteration I have a pair of x and y (xloc and yloc) to compare to the coordinates in the cell array, and if found, extract the corresponding ID and indices to a new matrix.
curScan is an indexing variable for the main loop that goes up to 99.
Here's what I got so far:
detectedAsTrack = 0;
detectedTracksList = [];
if find(xStates{curScan,1}(1,:)==xloc, 1) > 0 && find(xStates{curScan,1}(2,:)==yloc,1) > 0
detectedAsTrack = 1;
detectedTracksList(curScan) = xStates{curScan,2} (insert index for ID that corresponds to xloc and yloc);
end
  댓글 수: 2
Chris
Chris 2021년 10월 29일
xStates{curScan,1}(1,:) only inspects the first row of each matrix. Is that what you're trying to do, or do you want the column of x coordinates? (Same for the second comparison inspects the second row)
rbharrs
rbharrs 2021년 10월 29일
편집: rbharrs 2021년 10월 29일
@Chris So I actually want to check row 1 of every column for x, and row 2 of every column for y. This is what each cell on xStates{:,1} looks like:

댓글을 달려면 로그인하십시오.

채택된 답변

Chris
Chris 2021년 10월 29일
편집: Chris 2021년 10월 29일
detectedAsTrack = 0;
detectedTracksList = [];
idxs = xStates{curScan,1}(1,:)==xloc > 0 & xStates{curScan,1}(2,:)==yloc;
if any(idxs)
detectedAsTrack = 1;
detectedTracksList(curScan) = xStates{curScan,2}(idxs);
end

추가 답변 (0개)

카테고리

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

제품

Community Treasure Hunt

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

Start Hunting!

Translated by