How to display the answer got from .m file in GUI -- in edit box

조회 수: 1 (최근 30일)
Subha
Subha 2013년 3월 26일
Sir, I'm just experimenting with GUI ... i struck up in one point, where i need to call a .m file and to display its value in the edit box... i called the .m file as per http://www.mathworks.in/matlabcentral/answers/4213-how-to-call-contents-from-an-m-file-into-gui-callback-functions
but the thing is how to display a value in edit box, my progeam is just to calculate GLCM, and to display Contrast, Correlation ,Energy and Homogenety, i averaged these values, now to display them in edit box
% to display contrast'C' is the variable which have contrast value
function edit1_Callback(hObject, eventdata, handles)
% hObject handle to edit1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
C= str2double(get(hObject, 'String'));
if isnan(C)
set(hObject, 'String', 0);
errordlg('Input must be a number','Error');
end
handles.C=C
guidata(hObject,handles)
Suggestions please...

채택된 답변

Mahdi
Mahdi 2013년 3월 26일
I would suggest that your .m is a function that gives a specific output. So, from the previous post (depending on how many outputs your .m file has), you can do this:
output1=mfilename;
% Might be [output1, output2]=mfilename depending on how many outputs you have
Now, if you want to set the value into the edit box, use the set() command
set(handles.editbox1, 'String', num2str(output1))
handles.editbox1 is the tag of the box that you want to edit and output1 is the value that you want to display.
  댓글 수: 10
Mahdi
Mahdi 2013년 4월 1일
When you run a .m file in a GUI, the variables in the .m file are not global and are kept internally in the .m file workspace. As a result, these variable names are not defined. This is why I suggested making it a function over creating global variables. (There are a lot of reasons to avoid globals)
Subha
Subha 2013년 4월 2일
ok sir,, i've searched in matlab answers and found that we can simply write the .m fine name and set the values to the editbox, like
grayyy_gui
set(handles.editbox1, 'String', num2str(F(1)))
where now grayyy_gui is a script .m file and F is a variable in it... ........ because of your suggestions oly i built a small gui for my application,, thanks a lot for this help sir..

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Environment and Settings에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by