choose two coordinates
조회 수: 2 (최근 30일)
이전 댓글 표시
hi there, i have a set of xy coordinates show in command window.So, I want to pick the coordinate where, there are the most many number repeated in y. here i attach the illustration for reference. see the attached for more information.
help me please.. thanks
댓글 수: 0
채택된 답변
Matt Tearle
2012년 4월 19일
idx = (y == mode(y));
x(idx)
y(idx)
or, if x and y are columns of a matrix
idx = (xy(:,2) == mode(xy(:,2)));
xy(idx,:)
EDIT TO ADD:
Note sure if I'm correctly interpreting your follow-up question, but try this (try a few times, because random numbers sometimes do strange things):
xy = randi(10,12,2); % Make some fake data
% Find the coordinates with the most equal y values
idx = (xy(:,2)==mode(xy(:,2)));
mostycoords = xy(idx,:);
% Take first and last coordinates
firstlast = mostycoords([1,end],:);
% Plot results
plot(xy(:,1),xy(:,2),'o',firstlast(:,1),firstlast(:,2))
axis([0,12,0,12])
추가 답변 (1개)
Image Analyst
2012년 4월 19일
Try this:
% Generate some sample data,
xy = [0 3; 1 2;3 4; 3 2; 2 5; 7 2; 3 9]
modeRowIndexes = xy(:,2) == mode(xy(:,2))
% Now we know the rows that have the mode in the second column.
% So now we can find the first and last row where they occur.
firstRow = find(modeRowIndexes, 1, 'first')
lastRow = find(modeRowIndexes, 1, 'last')
% Get the first occurrence (coordinate) into a 1 by 2 array.
firstCoordinate = [xy(firstRow, 1), xy(firstRow, 2)]
% Get the second occurrence (coordinate) into a 1 by 2 array.
lastCoordinate = [xy(lastRow, 1), xy(lastRow, 2)]
In the command window you'll see the explanation:
xy =
0 3
1 2
3 4
3 2
2 5
7 2
3 9
modeRowIndexes =
0
1
0
1
0
1
0
firstRow =
2
lastRow =
6
firstCoordinate =
1 2
lastCoordinate =
7 2
참고 항목
카테고리
Help Center 및 File Exchange에서 Data Distribution Plots에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!