HOW TO CALL AN EXTARNAL FUNCTION INTO A PUSHBUTTON CALLBACK FUNCTION

조회 수: 6 (최근 30일)
roshi choudhary
roshi choudhary 2013년 12월 2일
댓글: Walter Roberson 2013년 12월 2일
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