GUI slider error while using subplot
Show older comments

i want to use two sliders as max and min value of bwareaopen(img,[min max]) so whenever i dragg the first slider it just getting value one time not continually getting value so how i can get continous change in subplot by getting value of slider and update the subplot 2nd image ...code is below
function slider1_Callback(hObject, eventdata, handles)
% hObject handle to slider1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'Value') returns position of slider
% get(hObject,'Min') and get(hObject,'Max') to determine range of
% slider\
newwimg=handles.image;
slideimg=imbinarize(newwimg);
min=get(hObject,'Value');
BW3=bwareafilt(slideimg,[min 500]);
axes(handles.axes1);
subplot(2,1,1)
imshow(handles.image);
title('Partially segmented')
subplot(2,1,2);
imshow(BW3);
title('Segmentation using slider')
guidata(hObject,handles)
% --- Executes during object creation, after setting all properties.
function slider1_CreateFcn(hObject, eventdata, handles)
% hObject handle to slider1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: slider controls usually have a light gray background.
if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor',[.9 .9 .9]);
end
% addlistener(hObject, 'ContinuousValueChange', @(hObject, eventdata) slider1_Callback(hObject, eventdata, handles));
% --- Executes on slider movement.
function slider2_Callback(hObject, eventdata, handles)
% hObject handle to slider2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'Value') returns position of slider
% get(hObject,'Min') and get(hObject,'Max') to determine range of slider
% --- Executes during object creation, after setting all properties.
function slider2_CreateFcn(hObject, eventdata, handles)
% hObject handle to slider2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: slider controls usually have a light gray background.
if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor',[.9 .9 .9]);
end
4 Comments
Rik
on 27 Apr 2019
This time I edited your question for you. Next time, please use the tools explained on this page to make your question more readable.
As for your question: you shouldn't using these functions in your callback, they are much too slow. Create the axes objects once, and after that only change the CData property. In your title you describe getting an error, but in your question body I see no indication of where an error might occur.
Also, the slider callback is only executed when you release the slider, or when you clikc the arrow buttons. If you want a live update during the draging, you should hack something together using the ButtonDownFcn or move your project over to App Designer. You shouldn't be using GUIDE anyway.
Talha Meraj
on 27 Apr 2019
Rik
on 27 Apr 2019
I would really strongly advise you not to use that method. If live updates are important to you, switch to the App Designer.
But if you insist on re-inventing the wheel: you can use a mechanism similar to what I used in my WindowLevel FEX submission. If you don't see how you would do that, don't attempt to implement it, but use the uislider component of the App Designer (you can use the ValueChangingFcn to have a live update).
Talha Meraj
on 27 Apr 2019
Accepted Answer
More Answers (0)
Categories
Find more on Creating, Deleting, and Querying Graphics Objects in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!