Re: Access user input from command line
- From: "Ashwini Deshpande" <vd.ashwini@xxxxxxxxxxxxx>
- Date: Fri, 30 May 2008 04:25:04 +0000 (UTC)
"Jeremy " <jmwatt@xxxxxxxxxxx> wrote in message
<g1d20m$c47$1@xxxxxxxxxxxxxxxxxx>...
A rookie question here...varargin)
I am trying to create a GUI with an edit box for user input
and a push button which the user will press to "submit"
their input (I call the program "enter"). I then want to
manipulate this data through the command prompt (or another
m file).
I am unable to call the input (called "str" in the code
below) in the command prompt or through other m files (I get
the error: ??? Undefined function or variable 'str'.). My
code is below (the input is declared near the bottom of the
program):
function varargout = enter(varargin)
% ENTER M-file for enter.fig
% ENTER, by itself, creates a new ENTER or raises the
existing
% singleton*.
%
% H = ENTER returns the handle to a new ENTER or the
handle to
% the existing singleton*.
%
% ENTER('CALLBACK',hObject,eventData,handles,...) calls
the local
% function named CALLBACK in ENTER.M with the given
input arguments.
%
% ENTER('Property','Value',...) creates a new ENTER or
raises the
% existing singleton*. Starting from the left,
property value pairs are
% applied to the GUI before enter_OpeningFunction gets
called. An
% unrecognized property name or invalid value makes
property application
% stop. All inputs are passed to enter_OpeningFcn via
varargin.
%
% *See GUI Options on GUIDE's Tools menu. Choose "GUI
allows only one
% instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES
% Edit the above text to modify the response to help enter
% Last Modified by GUIDE v2.5 24-May-2008 21:42:45
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @enter_OpeningFcn, ...
'gui_OutputFcn', @enter_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
if nargin && ischar(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end
if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State,
varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT
% --- Executes just before enter is made visible.
function enter_OpeningFcn(hObject, eventdata, handles,
% This function has no output args, see OutputFcn.GUIDATA)
% hObject handle to figure
% eventdata reserved - to be defined in a future version of
MATLAB
% handles structure with handles and user data (see
% varargin command line arguments to enter (see VARARGIN)GUIDATA)
% Choose default command line output for enter
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes enter wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command
line.
function varargout = enter_OutputFcn(hObject, eventdata,
handles)
% varargout cell array for returning output args (see
VARARGOUT);
% hObject handle to figure
% eventdata reserved - to be defined in a future version of
MATLAB
% handles structure with handles and user data (see
GUIDATA)
% Get default command line output from handles structure
varargout{1} = handles.output;
% 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
as text
% Hints: get(hObject,'String') returns contents of edit1
% str2double(get(hObject,'String')) returns contentsGUIDATA)
of edit1 as a double
% --- Executes during object creation, after setting all
properties.
function edit1_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit1 (see GCBO)
% eventdata reserved - to be defined in a future version of
MATLAB
% handles empty - handles not created until after all
CreateFcns called
% Hint: edit controls usually have a white background on
Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'),
get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% hObject handle to pushbutton1 (see GCBO)
% eventdata reserved - to be defined in a future version of
MATLAB
% handles structure with handles and user data (see
%---------------PROBLEM AREA NEXT THREE LINES--------------
function edit1_Callback(hObject, eventdata, handles)
str = get(handles.edit1,'String')
% --- Executes on button press in pushbutton1.
%BELOW IS THE CODE MAKING THE PUSHBUTTON CLOSE THE WINDOW
function pushbutton1_Callback(hObject, eventdata, handles)
close(handles.figure1);
I know, its pretty pathetic...can anyone help?
Hai,
If u want to access the string from command prompt use
evalin command. If u want to access it from the another GUI
or m_file use the command findobj.
one more method is to make the string global variable and
call it from anywhere in m_file or from any file in the
current working directory.
H2H,
Ashwini
.
- References:
- Access user input from command line
- From: Jeremy
- Access user input from command line
- Prev by Date: Need help to use 'quadgk' in 'dblquad'
- Next by Date: Re: Need help to use 'quadgk' in 'dblquad'
- Previous by thread: Access user input from command line
- Next by thread: File help
- Index(es):