HOW TO CALL AN EXTARNAL FUNCTION INTO A PUSHBUTTON CALLBACK FUNCTION

5 次查看(过去 30 天)
function pushbutton1_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
[FileName, folderName] = uigetfile('*.*','specify an image file');
fullimageFilename=fullfile(folderName,FileName);
im=imread(fullimageFilename);
image(im,'parent',handles.axes3);
NOW I WANT TO CALL A FUNCTION INTO THIS CALLBACK FUNCTION WHICH WILL TAKE IMAGE AS INPUT AND WILL CALULATE COLOR MOMENT OF THAT IMAGE AND SHOW THAT IMAGE IN GUI.
PLEASE HELP ME ABOUT THIS

回答(2 个)

ES
ES 2013-12-2
You can just have a function call to that function with necessary inputs. support you want to pass im to the function function1(inputMatrix), then call it under the button callback, like this..
function pushbutton1_Callback(hObject, eventdata, handles)
[FileName, folderName] = uigetfile('*.*','specify an image file'); fullimageFilename=fullfile(folderName,FileName); im=imread(fullimageFilename); image(im,'parent',handles.axes3);
function1(im);
Make sure that function1 is in the matlab path. Or better, place it in the same folder as the GUI's files(fig and m), or even much better, copy function1 into the m file of the GUI and call it.
  2 个评论
roshi choudhary
roshi choudhary 2013-12-2
sorry, i have tried this already but it didn't work out for me.......can you suggest some other method
Walter Roberson
Walter Roberson 2013-12-2
What happened when you tried it? Did you get an error message? Did you try giving the command line command
dbstop if error
and then running, and trying to debug the problem when the error occurs ?

请先登录,再进行评论。


Walter Roberson
Walter Roberson 2013-12-2
Just before the image() call, add
this_color_moment = calculate_color_moment(im);
where calculate_color_moment is the name of the appropriate function.
There does not seem to be much point in calculating the color moment when you do not do anything with the result.

类别

Help CenterFile Exchange 中查找有关 Interactive Control and Callbacks 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by