choose two coordinates
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
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 comentarios
Respuesta aceptada
Matt Tearle
el 19 de Abr. de 2012
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])
Más respuestas (1)
Image Analyst
el 19 de Abr. de 2012
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
Ver también
Categorías
Más información sobre Data Distribution Plots en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!