MATLAB: Imshow, axes in GUI, cla not working

axesdigital image processingguiMATLAB

Hello,
Number of axes created for displaying image depends on the slider value. switch slidervalue with two case is shown below:
switch slidervalue
case 1
RA = axes('units','pixels','Position',[350 12 868 320]); axes(RA); cla;
imshow(firstM); title(['D = : ', num2str(DISTANCE(1))]);
case 2
RA1 = axes('units','pixels','Position',[368 9 418 320]); axes(RA1); cla;
imshow(firstM); title(['D = : ', num2str(DISTANCE(1))]);
RA2 = axes('units','pixels','Position',[802 9 418 320]); axes(RA2); cla;
imshow(secondM); title(['D = : ', num2str(DISTANCE(2))]);
after case 1(shown image by RA axes), if second call is for case 2 – it will overwrite the case 1 image.(Case 2 images shown on case 1 image) most part of case 1 image is still visible
I think cla is not working. Tried this also: axes property- NextPlot value = replace, new, replacechildren, etc. that didn't work. reset , delete axes also didn't work.
can anyone provide solution:? I want to clear axes before displaying other ones…

Best Answer

This is because RA axes is still visible and you are creating one axe every time,
to create just one axe try this code outside your function right at the beginning of the file, after the 'Do not edit' and the guidata command line (I'm assuming some characteristics of your code, did you created with GUIDE? or else, upload your code!):
% Choose default command line output for WHATEVER.m
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
handles.RA = axes('units','pixels','Position',[350 12 868 320]);
handles.RA1 = axes('units','pixels','Position',[368 9 418 320]);
handles.RA2 = axes('units','pixels','Position',[802 9 418 320]);
guidata(hObject,handles);
And then have the handles values passed to your function...
function slider_Fnc_Callback(hObject,EventData,handles)
switch slidervalue
case 1
set(handles.RA,'Visible','on');
set(handles.RA1,'Visible','off');
set(handles.RA2,'Visible','off');
axes(handles.RA); cla; imshow(firstM);
title(['D = : ', num2str(DISTANCE(1))]);
case 2
set(handles.RA,'Visible','off');
set(handles.RA1,'Visible','on');
set(handles.RA2,'Visible','on');
axes(handles.RA1); cla; imshow(firstM);
title(['D = : ', num2str(DISTANCE(1))]);
axes(handles.RA2); cla; imshow(secondM);
title(['D = : ', num2str(DISTANCE(2))]);
Or something like this!