MATLAB: Eval in GUI does not execute

digital image processingevalgui

I am new to GUI design and coding. I have the following in my code but when I fill in my edit text box with a command
im2bw(im);
it does not run when I hit the button. I double-checked the pushbutton tag and it is correct.
function pushbutton8_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton8 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global im
s = get(handles.edit1,'string');
eval(s)
axes(handles.axes1);
imshow(im);

Best Answer

So what exactly does happen?
Matlab variables (except for objects of a handle-derived class in OOP) are not passed to functions by reference, rather by value. So just calling
im2bw(im);
would do the calculation then throw the result away. Then you simply plot the image afterwards.
So assuming there were no errors and all you saw was your final image that would be the reason.
I never use either global variables (I assume im does actually exist at that point) or eval, but I imagine if you enter:
im = im2bw(im);
into the edit box it may work. (Or manipulate the string from the edit box to add that in in the function rather than the user having to do it.