How to Use Edit Text in GUI in creating a filename?
Mostrar comentarios más antiguos

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!
Respuestas (2)
Dishant Arora
el 25 de Feb. de 2014
function edit1_callback(hObject, eventdata, handles)
fileName = get(hObject, 'string');
setappdata(0, 'name', fileName);
f = getappdata(0, 'name');
11 comentarios
John Hubert
el 25 de Feb. de 2014
Dishant Arora
el 25 de Feb. de 2014
Editada: Dishant Arora
el 25 de Feb. de 2014
Execute the fileName using feval inside pushbutton callback.
feval(f) or feval(getappdata(0,'name'))
John Hubert
el 25 de Feb. de 2014
Editada: John Hubert
el 25 de Feb. de 2014
Dishant Arora
el 25 de Feb. de 2014
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
el 25 de Feb. de 2014
Editada: John Hubert
el 25 de Feb. de 2014
Dishant Arora
el 25 de Feb. de 2014
Editada: Dishant Arora
el 25 de Feb. de 2014
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
el 25 de Feb. de 2014
John Hubert
el 25 de Feb. de 2014
Editada: John Hubert
el 25 de Feb. de 2014
Image Analyst
el 25 de Feb. de 2014
I tried.
Dishant Arora
el 25 de Feb. de 2014
Editada: Dishant Arora
el 25 de Feb. de 2014
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
el 25 de Feb. de 2014
I don't know why you're asking the user there. Why not just use uiputfile()?
Image Analyst
el 25 de Feb. de 2014
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);
Categorías
Más información sobre Desktop en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!