Zoom and Data Cursor callbacks used with saved figures
5 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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
0 commentaires
Réponses (1)
Jan
le 4 Oct 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 commentaires
Jan
le 5 Oct 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.
Voir également
Catégories
En savoir plus sur Data Exploration dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!