MATLAB: GUI slider error while using subplot

gui slidersubplot using axes

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

Best Answer

Your slider2 callback function is empty. You need to put code in there. What I'd recommend is that each slider simply call a function called SliderMoved(handles) and have each callback call that. Then in there you can get the value of each slider and do something with your image.
function slider1_Callback(hObject, eventdata, handles)
SliderMoved(handles)
end
function slider2_Callback(hObject, eventdata, handles)
SliderMoved(handles)
end
function SliderMoved(handles)
sliderValue1 = handles.slider1.Value;
sliderValue2 = handles.slider2.Value;
% etc. -- do something with these values.