Why does a callback get executed while clicking the mouse and not while releasing it in MATLAB 7.0 (R14)?
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
In MATLAB 6.0 I execute the following lines of code
figure(1);peaks
uimenu(1,'label','2D','callback','view(2);axis equal')
uimenu(1,'label','3D','callback','view(3);axis normal')
In the figure window notice that two tabs '2D' and '3D' get displayed. If you click on the 2D tab, a 2D plot appears in the axes. Click on 3D tab to make a 3D plot appear on the same axes. Mouse release activates the callbacks in this case.
In MATLAB 7.0 I execute the same code. Again in the figure window two tabs '2D' and '3D' appear. Click on the 2D tab to make a 2D plot appear on the axes. Now move the mouse to the 3D plot and notice that we do not have to click on 3D to make a 3D plot appear. Just switching the mouse between 2D and 3D toggles between the 2D and 3D plots in the axes.The mouse position itself activates the callbacks in this case.
Réponse acceptée
MathWorks Support Team
le 27 Juin 2009
The behavior observed in MATLAB 7.0 is consistent with the way menu items appear in Windows. If one wishes to have callbacks implemented in the way it was done in MATLAB 6.0, one can use the 2D and the 3D items appearing under a single menu. This enables callback activation upon mouse button release. Refer to the example below:
function solution
figure(1);peaks;
g = uimenu('Label','Dimension');
uimenu(g,'Label','2D','Callback',@twodimension);
uimenu(g,'Label','3D','Callback',@threedimension);
function twodimension(hObject, eventdata, handles)
disp('2 d selected')
view(2)
function threedimension(hObject, eventdata, handles)
disp('3 d selected')
view(3)
0 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Interactive Control and Callbacks 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!