Zoom and Data Cursor callbacks used with saved figures

5 visualizzazioni (ultimi 30 giorni)
Hy Guys,
I have the 'main' method where I plot a figure and I call two callbacks: one for zoom and one for data cursor:
function myMainFunction()
...
% plot normalized points
s = scatter(sensorSNorm, sensorDNorm, 20, [colorMatrixCurrent(:,1) colorMatrixCurrent(:,2) colorMatrixCurrent(:,3)], 'o', 'filled');
s.MarkerEdgeColor = 'k';
hcb = colorbar('YTickLabel', tempCellArray);
colormap(colorsColormap);
noColors = length(tempCellArray);
dy = 1/noColors/2;
Tick = linspace(0+dy, 1-dy, noColors);
set(hcb,'YTick',Tick);
xlabel('S[%]');
ylabel('D[%]');
% callback for data cursor
dcm_obj = datacursormode(gcf);
set(dcm_obj,'UpdateFcn',{@UpdateDataCursorSD, handles.parametersFromFile.time(currentIndex,1)})
% callback for zooming
hZoom = zoom(gcf);
set(hZoom, 'ActionPostCallback', {@UpdateColorMap, handles});
end
When I run myMainFunction and I apply the zooming and the data cursor on the generated figure, both zooming and datacursor work as expected.
But if I save the figure and I open it later by double clicking it, the zooming doesn't work anymore, but the data cursor does. Moreover, the breakpoint that I set in the UpdateDataCursorSD callback method is reached while using the data cursor on the figure, but the breakpoint in UpdateColorMap is never reached when zooming on the saved figure.
Do you have any idea why the zooming does not work on the figure that I open without running myMainFunction?
Thank you, Irina

Risposte (1)

Jan
Jan il 4 Ott 2017
Note that the elements of the figure have new handles after loading. Then
hZoom = zoom(gcf);
set(hZoom, 'ActionPostCallback', {@UpdateColorMap, handles});
should be destroyed. This means that you cannot store a zoom function such, that it is restored by a load command. You need to re-create it dynamically.
  2 Commenti
Irina Vermesan
Irina Vermesan il 4 Ott 2017
Thanks, Jim. There are two things I do not understand now:
1. if the elements of the figure have new handles, how come the data cursor callback still works on the new handles?
2. any suggestions on how to dynamically recreate the zoom function?
Thank you.
Jan
Jan il 5 Ott 2017
Who is Jim?
You can use the debugger to find the explanation: Set a breakpoint and try to find out, from where it is called. If e.g. gcbo is used there, it does not depend on a fixed content of a handle.
Add a CreateFcn, which is called during opening the figure:
FigH = figure('CreateFcn', @myOpenCallback);
savefig(FigH, 'test.fig');
close(FigH);
disp('Closed');
openfig((test.fig');
disp('Opened');
and the callback function:
function myOpenCallback(FigH, EventData)
disp('Hello');
Inside this callback you can initialize the zooming again.

Accedi per commentare.

Categorie

Scopri di più su Data Exploration in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by