
Displaying information about the data set by clicking on its plot not working when I run the program more than once
2 次查看(过去 30 天)
显示 更早的评论
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:

The problem is, when I try to run the program again, without closing it, this info box does not work:

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 个评论
采纳的回答
darova
2020-3-24
This is a bad idea to find appropriate data

better use pdist2
D = pdist(pos(:)',[xdata(:) ydata(:)]);
[~,j] = min(D);
2 个评论
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!