find row of point in plot

Hello.
This is my first post here, so hello to all of you out there. Maybe this is an old problem, but I couldn't find a solution here.
I have created an simple 3D plot with pareto-optimal points. From a massive m x n matrix only the last 3 n values are plotted (the fitness function).
Now is there an easy way to find the row of a point which is selected in the 3D plot with the data cursor (so I could find the corresponding decision vector)?
(like klicking on an excel plot...)
Thanks, Ruben

3 comentarios

Matt Tearle
Matt Tearle el 25 de Feb. de 2011
MATLAB Answers seems to be having issues right now, so while we wait, can I ask: is this something you'll want to do a lot?
Ruben
Ruben el 25 de Feb. de 2011
Yes, I will use quite a lot.
For now it's for checking the optimization process. Later I want to do some comparisons between runs.
I can export the data tip into the workspace and check with find and ismember, bt that is too complicated :(
Matt Tearle
Matt Tearle el 25 de Feb. de 2011
OK, try the function I put in the second half of my answer

Iniciar sesión para comentar.

 Respuesta aceptada

Matt Tearle
Matt Tearle el 25 de Feb. de 2011

0 votos

Here's an interactive approach:
% Make some data
data = rand(10,3);
otherdata = randi(5,10,3)
% Plot
plot3(data(:,1),data(:,2),data(:,3),'o')
% Now select data cursor, pick a point, right-click and "export cursor data to workspace"
clickedpoint = cursor_info.Position
% Get the row index
find(all(bsxfun(@eq,data,clickedpoint),2))
% Or, alternatively, get the other data directly, using logical indexing
otherdata(all(bsxfun(@eq,data,clickedpoint),2),:)
If you want to do this a lot, here's an idea for a function that does something like you're asking (I think)
function dataout = getpointsfromplot3(x,y,z,data)
h = plot3(x,y,z,'o');
hax = gca;
hfig = get(hax,'parent');
set(h,'ButtonDownFcn',@findpt);
uiwait(hfig);
function findpt(~,~)
cp = get(hax,'CurrentPoint');
drn = diff(cp);
drn = drn/norm(drn);
D = [x-cp(1,1),y-cp(1,2),z-cp(1,3)];
D = bsxfun(@rdivide,D,sqrt(sum(D.^2,2)));
D = bsxfun(@minus,D,drn);
[~,k] = min(sum(abs(D),2));
line(x(k),y(k),z(k),'marker','*','linestyle','none')
dataout = data(k,:);
set(h,'ButtonDownFcn',[]);
uiresume(hfig);
end
end
Cut'n'paste that, then try it out:
data = rand(10,3);
otherdata = randi(5,10,3)
getpointsfromplot3(data(:,1),data(:,2),data(:,3),otherdata)

1 comentario

Ruben
Ruben el 27 de Feb. de 2011
Thank you very much. It works very well.
Had to replace the tildes with dummy variables because it caused errors.
Now trying to understand what you where doing :)
bsxfun is nice, didn't know it before...

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Data Type Identification en Centro de ayuda y File Exchange.

Preguntada:

el 25 de Feb. de 2011

Community Treasure Hunt

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

Start Hunting!

Translated by