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!

채택된 답변

darova
darova 2020년 3월 24일
This is a bad idea to find appropriate data
better use pdist2
D = pdist(pos(:)',[xdata(:) ydata(:)]);
[~,j] = min(D);

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Get Started with MATLAB에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by