2014-08-28 77 views
1

我正在研究一個程序並決定在其周圍構建一個GUI。我想從頭開始很簡單,加載一個電影,並能夠滾動瀏覽。我已經看過很多關於聽衆的問題,實際上有人問這個問題,但是那裏的解決方案似乎對我沒有任何作用。在GUI中的我開啓功能 我連續滑塊偵聽器創建一個新的空白圖

  handles.output = hObject; 
     handles.sliderListener = addlistener(handles.Image_Slider,'ContinuousValueChange', ... 
               @(hObject, event) Image_Slider_ContValueCallback(... 
               hObject, eventdata, handles)); 
     % Update handles structure 
     guidata(hObject, handles); 

    And then I have the following two call backs : 
    function Image_Slider_Callback(hObject, eventdata, handles) 
    % hObject handle to Image_Slider (see GCBO) 
    % eventdata reserved - to be defined in a future version of MATLAB 
    % handles structure with handles and user data (see GUIDATA) 
    handles=guidata(hObject); 
    current_slice = round(get(handles.Image_Slider,'Value')); 
    %size(handles.Image_Sequence_Data(:,:,current_slice)); 


im =imagesc(handles.Image_Sequence_Data(:,:,current_slice),'Parent',handles.Image_Sequence_Plot); 
colormap('gray'); 

的正常工作(不聽者的一切行爲會正確)

,然後我也有

function Image_Slider_ContValueCallback(hObject, eventdata, handles) 
% hObject handle to Image_Slider (see GCBO) 
% eventdata reserved - to be defined in a future version of MATLAB 
% handles structure with handles and user data (see GUIDATA) 
handles=guidata(hObject); 
current_slice = round(get(handles.Image_Slider,'Value')); 
%size(handles.Image_Sequence_Data(:,:,current_slice)); 
handles=guidata(hObject); 

%im = 
imagesc(handles.Image_Sequence_Data(:,:,current_slice),'Parent',handles.Image_Sequence_Plot); 
colormap('gray'); 

,我覺得應該叫當滑塊連續移動時。我的問題是每次滑塊值改變一個空白(「圖1」)出現。實際的GUI數據響應正確,但我不明白爲什麼/這個'流氓'的數字來自哪裏..

有人請幫忙。此外,任何意見imshow與imagesc哪個更好(這個GUI將涉及大量的用戶與圖像交互)

回答

1

我幾乎有同樣的問題一次!我沒有獲得Matlab的現在,所以我不能測試工作的例子,但就目前而言,我建議放置這一行:

handles.sliderListener = addlistener(handles.Image_Slider,'ContinuousValueChange', ... 
               @(hObject, event) Image_Slider_ContValueCallback(... 
               hObject, eventdata, handles)); 
在滑塊的CreateFcn

。也許每次移動滑塊時都會出現一個空白圖形,因爲它不知道它已鏈接到偵聽器對象,因此會連續創建一個。

如果它不工作,你可以調用一個函數GUI來更新您的軸顯示的當前幀,例如外:

handles.sliderListener = addlistener(handles.Image_Slider,'ContinuousValueChange', ... 
               @(a,b) UpdateCurrentFrame); 

,而不是在你的GUI回調。 a和b是虛擬輸入參數,例如,UpdateCurrentFrame可以簡單地包含對imshow的調用。這可能不是最優雅的方式,但它對我來說非常合適。

哦,至於你關於imagesc和imshow的問題,我個人更喜歡imshow。在我的情況下,我使用文本註釋和矩形進行投資回報率選擇等等,並且對於imagesc沒有正確更新或長方形被卡住的問題,imagec幾乎沒有問題......但可能是因爲我沒有正確使用它。

希望有幫助!

+0

謝謝你的工作完美! – 2014-09-04 00:11:48

+0

非常高興幫助! – 2014-09-05 01:10:36