![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/279166/image.png)
Displaying information about the data set by clicking on its plot not working when I run the program more than once
1 view (last 30 days)
Show older comments
Pedro Augusto de Castro e Castro
on 24 Mar 2020
Commented: darova
on 27 Mar 2020
Hello,
So, I have a GUI and in this GUI I have several axis, and plots. In one of those plots I made a code to display info about the data set by clicking on it:
% --- Executes on mouse press over axes background.
function graph_5_ButtonDownFcn(hObject, eventdata, handles)
% hObject handle to graph_5 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
x = handles.DenPot;
y = handles.Rend;
x_mat = handles.x_mat;
y_mat = handles.y_mat;
PartNumberHS = handles.PartNumberHS;
ConfigHS = handles.ConfigHS;
% datacursormode(handles.graph_5, 'on')
% dcm = datacursormode(handles.graph_5);
datacursormode(handles.figMainWindow, 'on') %on
% dcm = datacursormode(gcf);
dcm = datacursormode(handles.figMainWindow);
set(dcm,'UpdateFcn',@(t,e) myupdatefcn(t,e,x,y,x_mat,y_mat, PartNumberHS, ConfigHS) );
where:
function txt = myupdatefcn(~,event,xdata,ydata,x_mat,y_mat, PartNumberHS, ConfigHS)
pos = get(event,'Position');
dts = get(event.Target,'Tag');
[~,j]= find( xdata==pos(1) & ydata==pos(2) );
% xdata(1,:) = xdata(1,:) / 1000;
% j=j(1);
txt = {dts,...
['Densidade de Potência: ', num2str(pos(1)), ' [kW/dm³]'],...
['Rendimento: ', num2str(100 * pos(2)), ' [%]'],...
['Frequência de Chaveamento: ', num2str(xdata(1,j)), ' [Hz]' ],...
['Material do Indutor: ', x_mat{j}]...
['Dissipador: ', PartNumberHS{j}]...
['Configuração: ', ConfigHS{j}]};
end
It works great if I run the program just once:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/279134/image.png)
The problem is, when I try to run the program again, without closing it, this info box does not work:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/279135/image.png)
How can I fix this error?
Other thing, like I said, I have several other plots, and I don't want those plots to display this info box when I click them, and this is happening right now.
Thanks in advance!
0 Comments
Accepted Answer
darova
on 24 Mar 2020
This is a bad idea to find appropriate data
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/279166/image.png)
better use pdist2
D = pdist(pos(:)',[xdata(:) ydata(:)]);
[~,j] = min(D);
2 Comments
More Answers (0)
See Also
Categories
Find more on 2-D and 3-D Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!