HOW TO CALL AN EXTARNAL FUNCTION INTO A PUSHBUTTON CALLBACK FUNCTION

5 views (last 30 days)
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

Answers (2)

ES
ES on 2 Dec 2013
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 Comments
roshi choudhary
roshi choudhary on 2 Dec 2013
sorry, i have tried this already but it didn't work out for me.......can you suggest some other method
Walter Roberson
Walter Roberson on 2 Dec 2013
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 ?

Sign in to comment.


Walter Roberson
Walter Roberson on 2 Dec 2013
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.

Categories

Find more on Interactive Control and Callbacks in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!