Why eval in GUI does not execute?

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);

 採用された回答

Adam
Adam 2015 年 5 月 2 日

0 投票

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.

1 件のコメント

Daniel N
Daniel N 2015 年 5 月 3 日
XD I forgot about that.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeShifting and Sorting Matrices についてさらに検索

質問済み:

2015 年 5 月 2 日

コメント済み:

2015 年 5 月 3 日

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by