Get variable from edittext

Hey, basicly I made a gui with 3 inputtext fields and a button. When pressing the button it should put the data from the input field into a variable and then start a function with these variables. If i declare the variables with just a regular variable it seems to work.(see commented example) How do i read the edittext?
% --- Executes on button press in pushbutton1.
function pushbutton1_Callback(hObject, eventdata, handles)
disp('start running code');
handles = guidata(hObject);
var1 = get(handles.edit1, 'string');
var2 = get(handles.edit2, 'string');
var3 = get(handles.edit3, 'string');
%var1 = 2;
%var2 = 0.5;
%var3 = 300;
freessimulatie(var1,var2,var3);

 采纳的回答

I fixed it.
I used this instead.
edit1 = findobj(0, 'tag', 'edit1');
var1 = str2double( get(edit1, 'string') );
edit2 = findobj(0, 'tag', 'edit2');
var2 = str2double( get(edit2, 'string') );
edit3 = findobj(0, 'tag', 'edit3');
var3 = str2double( get(edit3, 'string') );

更多回答(1 个)

var1 = str2double( get(handles.edit1, 'string') );
var2 = str2double( get(handles.edit2, 'string') );
var3 = str2double( get(handles.edit3, 'string') );

2 个评论

I still get errors. This is what I get
Dot indexing is not supported for variables of this type.
Error in calculateBerekening>pushbutton1_Callback (line 83) var1 = str2double( get(handles.edit1, 'string') );
Error in gui_mainfcn (line 95) feval(varargin{:});
Error in calculateBerekening (line 42) gui_mainfcn(gui_State, varargin{:});
Error in matlab.graphics.internal.figfile.FigFile/read>@(hObject,eventdata)calculateBerekening('pushbutton1_Callback',hObject,eventdata,guidata(hObject)) Error while evaluating UIControl Callback.
That implies that handles was not a handles structure, which is a problem that would be associated with CreateFcn but not with pushbutton callbacks.

请先登录,再进行评论。

类别

帮助中心File Exchange 中查找有关 Data Type Identification 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by