Unable to update data tip using custom update function

조회 수: 50 (최근 30일)
Melwin Thomas
Melwin Thomas 2020년 6월 24일
댓글: Melwin Thomas 2020년 6월 25일
Hi,
I have written a code to have a data tip with higher resolution. Please find the sample below:
% Get Screensize
scrsz = get(groot,'ScreenSize');
% Create a figure
fh =figure('Position',[10 10 scrsz(3)/1.1 scrsz(4)/1.1]);
plot(rand(1,100))
DataCursorMode1 = datacursormode(fh);
% Call the custom update function
set(DataCursorMode1,'Enable','on','UpdateFcn',@displayCoordinates)
% Save the Matlab figure
savefig(fh,[Path '.fig']);
% Close the figure
close (fh);
The custom update function is shown below:
function txt = displayCoordinates(~, info)
txt = {sprintf('X: %.5f', info.Position(1)), sprintf('Y: %.5f', info.Position(2))};
end
The Matlab figure is being saved in a shared drive. When i open it in my computer the data tip is shown as expected(with higher resolution).
But when somebody tries to open it in a different computer(with the same Matlab version 2018a). The data tip doesn't work anymore. It gives the following error on the figure:
Unable to update data tip using custom update function
I don't understand what is going wrong here. Does anybody have any clue? Appreciate your time and help.
  댓글 수: 3
Melwin Thomas
Melwin Thomas 2020년 6월 24일
Hi Geoff,
Thank you for your response.
I thought the same and I shared it with them. And they have the displayCoordinates function in the same directory as mine. Still no luck.
Fangjun Jiang
Fangjun Jiang 2020년 6월 24일
I was able to duplicate the problem. Using your script, the figure was created and saved. The data tip behaved as expected.
Close MATLAB. Open the saved .fig, it shows "unable to update data tip using custom update function". Add displayCoordinates.m function into the path. Still the same problem.
Looking for something that saves the custom update function with the figure, if even possible.

댓글을 달려면 로그인하십시오.

채택된 답변

Fangjun Jiang
Fangjun Jiang 2020년 6월 24일
It must be related to where the custom update function comes from when the figure is saved.
  1. I created and saved the figure first with displayCoordinates() as a local function. Close MATLAB and then open the figure, data tip has error even after displayCoordinates() is added as a function in the path.
  2. I created the displayCoordinates() function as a separate function and .m file first in the path. Then create and save the figure. Close MATLAB and open the figure, data tip shows properly.
  댓글 수: 1
Melwin Thomas
Melwin Thomas 2020년 6월 25일
Hi Fangjun Jiang,
Thank you very much for your response.
That was indeed the issue. The issue is resolved now. Appreciate your help.
Have a nice day.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Interactive Control and Callbacks에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by