How to display the answer got from .m file in GUI -- in edit box
現在この質問をフォロー中です
- フォローしているコンテンツ フィードに更新が表示されます。
- コミュニケーション基本設定に応じて電子メールを受け取ることができます。
エラーが発生しました
ページに変更が加えられたため、アクションを完了できません。ページを再度読み込み、更新された状態を確認してください。
古いコメントを表示
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
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 件のコメント
yes sir i tried with this... it leads an error... dono whre i've made wrong...
??? Too many output arguments.
Error in ==> phase2_test2>pushbutton2_Callback at 103 [Dat1, Dat2, Dat3, Dat4] = 'grayyy_gui';
Error in ==> gui_mainfcn at 96 feval(varargin{:});
Error in ==> phase2_test2 at 43 gui_mainfcn(gui_State, varargin{:});
Error in ==> @(hObject,eventdata)phase2_test2('pushbutton2_Callback',hObject,eventdata,guidata(hObject))
??? Error while evaluating uicontrol Callback
What yhould this line do:
[Dat1, Dat2, Dat3, Dat4] = 'grayyy_gui';
There is a string on the right. Do you mean:
[Dat1, Dat2, Dat3, Dat4] = grayyy_gui;
Subha
2013 年 3 月 28 日
no sir.... grayyy_gui is my file name ....
[Dat1, Dat2, Dat3, Dat4] is the output... frm grayyy_gui
Mahdi
2013 年 3 月 28 日
Did you change your mfile to a function that gives outputs? (It seems like you did, just making sure) Could it be that you're asking the grayyy_gui function to display more than the outputs that you made it able to? I would definitely check my grayyy_gui file and see if it matches. Maybe make sure that the function is in the same directory you're working in?
grayy_gui was a m file and not a function, i just tried with a function which gives 13 output, i made a push button and 13 edit boxes, now this is the error....
??? Error: File: haralicktest.m Line: 20 Column: 1
"i" previously appeared to be used as a function or command, conflicting with its use here as the name of a
variable.
A possible cause of this error is that you forgot to initialize the
variable, or you have initialized it implicitly using load or eval.
Error in ==> matlab_test>pushbutton1_Callback at 81
[Dat1, Dat2, Dat3, Dat4, Dat5, Dat6, Dat7, Dat8, Dat9, Dat10, Dat11, Dat12, Dat13] = haralicktest;
Error in ==> gui_mainfcn at 96
feval(varargin{:});
Error in ==> matlab_test at 42
gui_mainfcn(gui_State, varargin{:})
we have handles and hOject, i need to assign something like that...
Subha
2013 年 3 月 28 日
yes sir,, i kept both files in same directory.... http://www.mathworks.com/matlabcentral/fileexchange/36233-haralick/content/haralick.m
i'm trying with this program...
I glanced at the other code briefly and it has only F as an output. So you would need to do this:
F=grayyy_gui;
Since this matrix has 13 outputs, it depends which ones you want to show. For example, you can show the first value by:
set(handles.editbox1, 'String', num2str(F(1)))
And you can do this for all other values as well.
Subha
2013 年 3 月 31 日
Thanks alot sir... now its working,,, now i ve another doubt.. instead of function i jst included .m script file, i've so many outputs in it.. when i try to display particular values in the editbox.. it gives error as "variable name" is undefined...
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
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 件)
カテゴリ
ヘルプ センター および File Exchange で MATLAB についてさらに検索
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Web サイトの選択
Web サイトを選択すると、翻訳されたコンテンツにアクセスし、地域のイベントやサービスを確認できます。現在の位置情報に基づき、次のサイトの選択を推奨します:
また、以下のリストから Web サイトを選択することもできます。
最適なサイトパフォーマンスの取得方法
中国のサイト (中国語または英語) を選択することで、最適なサイトパフォーマンスが得られます。その他の国の MathWorks のサイトは、お客様の地域からのアクセスが最適化されていません。
南北アメリカ
- América Latina (Español)
- Canada (English)
- United States (English)
ヨーロッパ
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
