Matlab GUI中带有滑块的WindowScrollWheelFcn [英] WindowScrollWheelFcn with slider in Matlab GUI

查看:518
本文介绍了Matlab GUI中带有滑块的WindowScrollWheelFcn的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在Matlab中制作一个GUI,该GUI可以滚动并显示约600幅医学图像.我有一个显示图像的轴,还有一个滚动条,当按下结束箭头时,滚动条可以一次浏览一次图像.

I'm making a GUI in Matlab that scrolls through and displays ~600 medical images. I have an axes on which the images are displayed, and a scrollbar that presently goes through images one at a time when the end arrows are pressed.

我正在尝试找出如何合并WindowScrollWheelFcn的方法,以便可以使用鼠标上的滚动更快地浏览图像.

I'm trying to figure out how to incorporate the WindowScrollWheelFcn so I can use the scroll on the mouse to go through the images faster.

这是我的代码:

function ct_slider_Callback(hObject, eventdata, handles)

set(gcf, 'WindowScrollWheelFcn', @wheel);
set(gcf, 'CurrentAxes', handles.ct_image_axes);
handles.currentSlice = round(get(handles.ct_slider, 'Value'));
imshow(handles.imageArray(:,:,handles.currentSlice));
text = sprintf('Slice number: %d', handles.currentSlice);
set(handles.ct_slice_number, 'String', text);
guidata(hObject, handles);

function wheel(hObject, callbackdata, handles)
    if callbackdata.VerticalScrollCount > 0
        handles.currentSlice = handles.currentSlice + 1;
    elseif callbackdata.VerticalScrollCount < 0
        handles.currentSlice = handles.currentSlice - 1;
    end
guidata(hObject,handles);

我不断收到错误消息:使用Image_GUI_new> wheel时输入参数不足."

I keep getting the error: "Error using Image_GUI_new>wheel Not enough input arguments."

我在Matlab中没有使用GUI的丰富经验,因此将不胜感激.

I don't have extensive experience with GUIs in Matlab so any help would be appreciated.

推荐答案

您非常接近!

默认情况下,按照定义的方式为回调函数分配2个输入参数:

By default, callback functions are assigned 2 input arguments when defined as you did:

set(gcf, 'WindowScrollWheelFcn', @wheel);

等同于

set(gcf, 'WindowScrollWheelFcn', @(DummyA,DummyB) wheel);

如果您需要添加输入参数(例如handles结构),则可以将所有输入变量(即2个必需变量以及您想要的任何变量)包装在单元格数组中,如下所示:

If you need to add an input argument, the handles structure for instance, you can wrap up all the input variables (i.e. 2 mandatory plus whatever you like) in a cell array as follows:

set(gcf, 'WindowScrollWheelFcn', {@wheel,handles});

因此,功能wheel接受2个强制输入+ handles结构.现在应该可以了.

Hence the function wheel accepts the 2 mandatory inputs + the handles structure. That should work now.

如果可以的话,重复使用imshow并不是很好的性能,如果要在ct_slider_Callback中连续显示许多图像,则可能要使用此技巧:

If I may, using imshow repetitively is not good performance-wise and you might want to use this trick if you are to display many images continuously in your ct_slider_Callback:

1)显示第一个图像(此处为数字1)时,将一个手柄作为输出分配给imshow.

1) When displaying the 1st image (here number 1), assign a handle as the output to imshow.

hShow = imshow(handles.imageArray(:,:,1));

2)然后,在执行回调时,无需再次调用imshow,而是更新创建的hShow句柄的cdata属性:

2) Then as the callback is executed, instead of calling again imshow, update the cdata property of the hShow handles created:

set(hShow,'cdata',handles.imageArray(:,:, handles.currentSlice)));

您可能会看到图像显示更流畅...

You might see that images are displayed more smoothly...

希望有帮助!

这篇关于Matlab GUI中带有滑块的WindowScrollWheelFcn的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆