How to Use Edit Text in GUI in creating a filename?
古いコメントを表示

Hi Guys. My main problem is how to create a filename through editText in GUI? kindly take a look on the picture. :") I just want to know on how to enter a name in "EditText" in GUI and that entered text will be the name/value for the variable 'f'. Thank you!
回答 (2 件)
Dishant Arora
2014 年 2 月 25 日
function edit1_callback(hObject, eventdata, handles)
fileName = get(hObject, 'string');
setappdata(0, 'name', fileName);
f = getappdata(0, 'name');
11 件のコメント
John Hubert
2014 年 2 月 25 日
Dishant Arora
2014 年 2 月 25 日
編集済み: Dishant Arora
2014 年 2 月 25 日
Execute the fileName using feval inside pushbutton callback.
feval(f) or feval(getappdata(0,'name'))
John Hubert
2014 年 2 月 25 日
編集済み: John Hubert
2014 年 2 月 25 日
Dishant Arora
2014 年 2 月 25 日
Ok, you want to use data from editbox in a m file. I didn't read it carefully. There are 2 ways to do it.First is to make your m file a function file and pass on the data as parameter like:
intializer1(f) % make sure to convert data using str2num if it's of class % % numerical
And 2nd way is to recover it in your m file using getappdata.
John Hubert
2014 年 2 月 25 日
編集済み: John Hubert
2014 年 2 月 25 日
Dishant Arora
2014 年 2 月 25 日
編集済み: Dishant Arora
2014 年 2 月 25 日
So, what's the problem?? you have filename stored in rootgui or do this:
function pushbutton1_Callback(hObject, eventdata, handles)
fileName = get(handles.edit1,'string')
initializer1(fileName) % if its a m file function
And if you don't want to make it function file then use setappdata and getappdata to store and recover filename.
John Hubert
2014 年 2 月 25 日
John Hubert
2014 年 2 月 25 日
編集済み: John Hubert
2014 年 2 月 25 日
Image Analyst
2014 年 2 月 25 日
I tried.
Dishant Arora
2014 年 2 月 25 日
編集済み: Dishant Arora
2014 年 2 月 25 日
Great!! works perfectly fine for me. Make sure you press correct push button. See what your error code says and let us know if it needs a spell check. This is so ignorant
Image Analyst
2014 年 2 月 25 日
I don't know why you're asking the user there. Why not just use uiputfile()?
Image Analyst
2014 年 2 月 25 日
John, all of this would probably be best done in gui.m rather than a separate file. If you're going to have your GUI_OpeningFcn() call initilializer.m then you should get rid of the clear and have it be a function where you pass in handles so that initializer.m will have access to all the GUI controls.
Then, don't call input() if the user is supposed to type something into the edit field. You just, at the appropriate time (which means after the user has typed something in), get the value with
filename = get(handles.edit1, 'String');
Or else you do ask for it with input(), or better yet inputdlg(), and then use set to send what they typed in to the edit field
userString = inputdlg(..... whatever....
% Stuff into edit field.
set(handles.edit1, 'String', userString);
カテゴリ
ヘルプ センター および File Exchange で Interactive Control and Callbacks についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!