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!

Respuestas (2)

Dishant Arora
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
John Hubert el 25 de Feb. de 2014
Thank you! this helped! :) I have another question, if the value/text entered in the edittext box in the 'gui' is going to be used inside an m-file (m-file activated by a pushbutton), how is that?
Dishant Arora
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
John Hubert el 25 de Feb. de 2014
Editada: John Hubert el 25 de Feb. de 2014
here's my code
function edit1_Callback(hObject, eventdata, handles)
num1 = get(hObject,'string');
handles.num1 = num1;
guidata(gcbo,handles);
function pushbutton3_Callback(hObject, eventdata, handles)
f = handles.num1
guidata(gcbo,handles);
eval('f')
initializer1
----------------------------
this "initializer1" is an m-file which uses the variable f. when I press this push button 3, it's always an error.I guess my m-file "initializer1" cant read variable "f". :'( :'( help me. :(
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
John Hubert el 25 de Feb. de 2014
Editada: John Hubert el 25 de Feb. de 2014
So i have to make it like this?
function edit1_Callback(hObject, eventdata, handles)
num1 = get(hObject,'string');
handles.num1 = num1;
guidata(gcbo,handles);
function pushbutton3_Callback(hObject, eventdata, handles)
f = handles.num1
guidata(gcbo,handles);
initializer(f)
hmmm, this is my mfile. after i made it into a function file, there is still error. and i don't know why. . . the variable 'f' is actually the "filename" that i need to create. the INput variable f to this-mfile is a string. :( :( :( :(
function initializer1(f)
output=wavread('renz N');
outnorm=(output-min(output))./(max(output)-min(output));
[b,a]=butter(9,3000/20000,'low');
y=filter(b,a,outnorm);
ynorm=(y-min(y))./(max(y)-min(y));
close; plot(ynorm)
wavwrite(ynorm,4500,f)
Dishant Arora
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.
as what you said, i made my code into this.
function edit1_Callback(hObject, eventdata, handles)
num1 = get(hObject,'string');
handles.num1 = num1;
guidata(gcbo,handles);
function pushbutton3_Callback(hObject, eventdata, handles)
fileName = get(handles.edit1,'string')
initializer1(fileName)
and the result in the command window is.
Error using wavwrite>OpenWaveWrite (line 162)
Wave file name must be a string.
Error in wavwrite (line 96)
fid = OpenWaveWrite(wavefile);
Error in initializer1 (line 9)
wavwrite(ynorm,4500,f)
Error in GuiNaItuu>pushbutton3_Callback (line 86)
initializer1(fileName)
Error in gui_mainfcn (line 96)
feval(varargin{:});
Error in GuiNaItuu (line 42)
gui_mainfcn(gui_State, varargin{:});
Error in
@(hObject,eventdata)GuiNaItuu('pushbutton3_Callback',hObject,eventdata,guidata(hObject))
Error while evaluating uicontrol Callback
John Hubert
John Hubert el 25 de Feb. de 2014
Editada: John Hubert el 25 de Feb. de 2014
Error still occurs. :'( :'( :'( these are my code files, if you do happen to have any .wav file, with all your kindness, kindly use it in my "initializer1" file (because my code needs a .wav file) :( help me. :( :(
I tried.
Dishant Arora
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
I don't know why you're asking the user there. Why not just use uiputfile()?

Iniciar sesión para comentar.

Image Analyst
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.

Etiquetas

Preguntada:

el 25 de Feb. de 2014

Comentada:

el 25 de Feb. de 2014

Community Treasure Hunt

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

Start Hunting!

Translated by