MATLAB Answers

External functions (with a GUI)

Hey there.
I'm currently working on a GUI, that has to show images in 3 different axes. I have no problem handling it insides the main *.m file for the GUI, but if i try to put the plotting code in a file for itself, then I can't use "axes(handles.axes1)" because handles, apparently, only can be accessed from the main file. Is there anyway to cope with this? And preferably something somewhat refined, since this is for my bachelor degree.
Thanks in advance

  댓글 수: 0

로그인 to comment.

답변 수: 3

Answer by Chandra Kurniawan on 20 Feb 2012
 Accepted Answer

Maybe this will helps.
I have GUI as shown in picture below :
For button "GRAY" and "BINARY", I perform image convertion with external functions.
I also call 'imshow' from external functions.
Here code about the main interface :
function pushbutton1_Callback(hObject, eventdata, handles)
handles.I = imread('peppers.png');
guidata(hObject, handles);
function pushbutton2_Callback(hObject, eventdata, handles)
handles.J = rgb_to_gray(handles.I,handles.axes2);
guidata(hObject, handles);
function pushbutton3_Callback(hObject, eventdata, handles)
handles.K = im_to_bw(handles.J,handles.axes3);
guidata(hObject, handles);
And here the external functions
Perform rgb2gray
function J = rgb_to_gray(I,handles)
J = rgb2gray(I);
Perform im2bw
function J = im_to_bw(I,handles)
J = im2bw(I);
I hope this will helps

  댓글 수: 0

로그인 to comment.

Answer by Jakob Sørensen on 21 Feb 2012

Got it to work, thanks to everyone contributing. To sum up (if anyone else has the same problem), what i needed was to use the "handle" variable when calling the external function. Like this:
output = functionName(input1, input2, ..., handle)
Otherwise you obviously can't use the "handle" in the external function. Once again, thanks.

  댓글 수: 2

on 30 Dec 2014
Thank you Jakob Sorensen. That was what I was looking for exactly.

로그인 to comment.

Answer by Walter Roberson
on 20 Feb 2012

  댓글 수: 1

I might be stupid here (in fact I probably am), but how do I use that info to get the handle data out to a function in a seperate m-mile?
I want to call it like this:
instead of having a code like this in the main m-file:

로그인 to comment.

Translated by