MATLAB: Diplay a dialog box when using a wrong callback using images in gui

guisave variable gui

I'm still learning how tu use GUI in matlab. i Have a gui that reads an image and display it. Then i have 3 buttons which converts the image into a grayscale image (R, G or B) then, using a slider, i set the threshold for a binary image. Well, when i use the slider without pressing any buttons (r, g or b) i get an error " Reference to non-existent fiel". And that's fine, i know i have to get an error there, but what i want to do is to display an error using waitfor(msgbox('')); when that error occurs. i'm still traying to do that, but i need a little help please.
Well, i want to use this gui when running a certain part from a code in a .mat file. For example. I run the code, read an image, then call the gui, binarize the same image, save the binarized image, and then use that saved image in the original code and continue the code. Hope it makes sense. How can i do this?
Here is the gui
function prueba_gui_OpeningFcn(hObject, eventdata, handles, varargin)
handles.output = hObject;
handles.imagen = imread('G:\Memoria\test\Imagen125.jpg');
axes(handles.axes1);
imshow(handles.imagen);
guidata(hObject, handles);
function varargout = prueba_gui_OutputFcn(hObject, eventdata, handles)
varargout{1} = handles.output;
function binar_Callback(hObject, eventdata, handles)
handles.output = hObject;
axes(handles.axes1);
tempImg = handles.im;
thresholdValue = get(handles.binar, 'value');
binaryImage = tempImg> thresholdValue;
se = strel('square',4);
w = imdilate(binaryImage,se);
imshow(w);
guidata(hObject,handles);
function binar_CreateFcn(hObject, eventdata, handles)
if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor',[.9 .9 .9]);
end
function RED_Callback(hObject, eventdata, handles)
handles.output = hObject;
axes(handles.axes1);
handles.im = handles.imagen(:,:,1);
imshow(handles.im);
guidata(hObject,handles);
function GREEN_Callback(hObject, eventdata, handles)
handles.output = hObject;
axes(handles.axes1);
handles.im = handles.imagen(:,:,2);
imshow(handles.im);
guidata(hObject,handles);
function BLUE_Callback(hObject, eventdata, handles)
handles.output = hObject;
axes(handles.axes1);
handles.im = handles.imagen(:,:,3);
imshow(handles.im);
guidata(hObject,handles);
% --- Executes on button press in save.
function save_Callback(hObject, eventdata, handles)
handles.output = hObject;
%nothing here yet

Best Answer

See the FAQ for how to share variables between different functions in your m-file. http://matlab.wikia.com/wiki/FAQ#How_can_I_share_data_between_callback_functions_in_my_GUI.28s.29.3F
Related Question