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);
  2 件のコメント
Pedro Augusto de Castro e Castro
Pedro Augusto de Castro e Castro 2020 年 3 月 27 日
Thank you for your input!
Unfortunately, this does not solve the problem.
darova
darova 2020 年 3 月 27 日
Can you attach the whole project? So i can experiment by myself?

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeGet Started with MATLAB についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by