MATLAB: Vector Input, GUI edit text box

gui edit text boxvector input

Hi,
I am trying to get a vector input from the user in a GUI using edit text boxe, but it seems that the program doesn't recognize the text boxes, although I have them in my GUI. Can someone tell what is the problem?
% --- Executes on button press in pushbutton1.
function pushbutton1_Callback(hObject, eventdata, handles)
% 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 GUIDATA)
Xn=str2num(get(handle.edit1,'string'));
Yn=str2num(get(handle.edit2,'string'));
dn=str2num(get(handle.edit3,'String'));
The class handle has no Constant property or Static method named 'edit1'.

Best Answer

The string from a edit box is returned as a cell array of characters. If the expected inputs are a comma separated vector such as "1, 2, 3.14, 5", here's how to exact those values.
s = handles.edit1.String;
d = str2double(strsplit(s{:}, ','));
I suggest using conditional error detection in order to provide the user with feedback in case they use an incompatible format.
s = handles.edit1.String;
try
d = str2double(strsplit(s{:}, ','));
catch
error('Edit field must contain comma separated values such as "6, 5, 3.14"')
end