External functions (with a GUI)

4 ビュー (過去 30 日間)
Jakob Sørensen
Jakob Sørensen 2012 年 2 月 20 日
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

採用された回答

Chandra Kurniawan
Chandra Kurniawan 2012 年 2 月 20 日
Hi,
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');
axes(handles.axes1);
imshow(handles.I);
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);
axes(handles);
imshow(J);
Perform im2bw
function J = im_to_bw(I,handles)
J = im2bw(I);
axes(handles);
imshow(J);
I hope this will helps

その他の回答 (2 件)

Jakob Sørensen
Jakob Sørensen 2012 年 2 月 21 日
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 件のコメント
Akmel
Akmel 2014 年 12 月 30 日
Thank you Jakob Sorensen. That was what I was looking for exactly.
Febrian Dhimas Syahfitra
Febrian Dhimas Syahfitra 2018 年 2 月 5 日
編集済み: Febrian Dhimas Syahfitra 2018 年 2 月 5 日

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


Walter Roberson
Walter Roberson 2012 年 2 月 20 日
  1 件のコメント
Jakob Sørensen
Jakob Sørensen 2012 年 2 月 20 日
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:
plotImage('imageName');
instead of having a code like this in the main m-file:
axes(handles.axes1);
imagesc(imageName);
set(handles.axes1,'blablabla'...)

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

カテゴリ

Help Center および File ExchangeAnnotations についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by