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 件のコメント

Matt Tearle
Matt Tearle 2011 年 2 月 25 日
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 2011 年 2 月 25 日
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 2011 年 2 月 25 日
OK, try the function I put in the second half of my answer

サインインしてコメントする。

 採用された回答

Matt Tearle
Matt Tearle 2011 年 2 月 25 日

0 投票

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 件のコメント

Ruben
Ruben 2011 年 2 月 27 日
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...

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File Exchange で Line Plots についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by