按住鼠标中键旋转Matlab图中的3d对象

时间:2020-03-08 22:52:52

标签: matlab user-interface figure

我有一个3D图,想使用按住鼠标中键的方式旋转它,但是释放中键时会立即禁用旋转

下面是代码段

obj=plot3(...);  % any 3d plot command
set(obj,'ButtonDownFcn',@startrotate);

function startrotate(src,evnt)
if strcmp(get(gcf,'SelectionType'), 'extend')
    rotate3d on;
    set(gcbf,'WindowButtonUpFcn',@stoprotate);
    return;
end

function stoprotate(src,hrot)
if strcmp(get(gcf,'SelectionType'), 'extend')
    rotate3d off;
    set(gcbf,'WindowButtonUpFcn','');
end

但是,我遇到一个错误:

Warning: Setting the "WindowButtonUpFcn" property is not permitted while this mode is active. 

打开rotate3d时,是否可以在matlab图形/ gui窗口中捕获按钮按下事件?

更新03/10/2020 遵循@Hoki的建议,我进行了以下更改

function startrotate(src,evnt)
if strcmp(get(gcf,'SelectionType'), 'extend')
    disp('start rotate');
    h=rotate3d;
    h.ActionPostCallback= @stoprotate;
    h.Enable = 'on';
    return;
end

function stoprotate(src,hrot)
if strcmp(get(gcf,'SelectionType'), 'extend')
    disp('stop rotate');
    h=rotate3d;
    h.Enable='off';
end

但是出现错误“ The current mode can not be interrupted”。看起来我无法在ActionPostCallback回调中关闭旋转功能。有什么方法可以在中键按下后禁用旋转功能?

0 个答案:

没有答案