MATLAB: Why do i get this error when i try add a working code to guide

feval error in guideMATLAB

Hi, i get the error below when trying to solve a D.E. whit euler:
I have a code that solves D.E. whit euler metod, but i have to add that code to a GUI (guide) like this one, i made it from a blank guide:
guide.PNG
The euler code is quite simple and it works in a script.
syms x
syms y
fprintf('\tResolucion de Ecuaciones Diferenciales por Metodo Euler');
f=inline(input('\n Ingrese la derivada:','s'));
x=input('\n Ingrese el valor de X inicial:');
xf=input('\n Ingrese el valor de X final:');
y=input('\n Ingrese el valor de Y inicial:');
h=input('\n Ingrese el paso:');
n=(xf-x)/h
disp(' x y');
for i=1:n+1
y1= feval(f,x,y);
hy1=h*y1;
fprintf('\n%0.1f %0.4f ',x,y);
y=y+hy1;
x=x+h;
end
The error i get is this:
Error using : (line 38)
Unable to compute number of steps from 1 to 5 - 2*x by 1.
Error in gui>bResolver_Callback (line 99)
for i=1:n+1
Error in gui_mainfcn (line 95)
feval(varargin{:});
Error in gui (line 42)
gui_mainfcn(gui_State, varargin{:});
Error in
matlab.graphics.internal.figfile.FigFile/read>@(hObject,eventdata)gui('bResolver_Callback',hObject,eventdata,guidata(hObject))
Error while evaluating UIControl Callback.
and here is the GUI(guide) code

function varargout = gui(varargin)
% GUI MATLAB code for gui.fig
% GUI, by itself, creates a new GUI or raises the existing
% singleton*.
%

% H = GUI returns the handle to a new GUI or the handle to
% the existing singleton*.
%
% GUI('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in GUI.M with the given input arguments.
%
% GUI('Property','Value',...) creates a new GUI or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before gui_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to gui_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 gui
% Last Modified by GUIDE v2.5 21-Jul-2019 19:03:38
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @gui_OpeningFcn, ...
'gui_OutputFcn', @gui_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 gui is made visible.
function gui_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject handle to figure

% eventdata reserved - to be defined in a future version of MATLAB

% handles structure with handles and user data (see GUIDATA)

% varargin command line arguments to gui (see VARARGIN)
% Choose default command line output for gui
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes gui wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = gui_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;
% --- Executes on button press in bResolver.
function bResolver_Callback(hObject, eventdata, handles)
% hObject handle to bResolver (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
clc;
opcion=get(handles.menuMetodo, 'Value');
%a=get(handles.Tecua, 'string');
a=inline(get(handles.Tecua, 'string'));
x=str2num(get(handles.Txo, 'string'));
y=str2num(get(handles.Tyo, 'string'));
xf=str2num(get(handles.Txf, 'string'));
h=str2num(get(handles.Tpaso, 'string'));
%disp(a)
%disp(x)
%disp( y )
%disp( xf )
%disp( h)
syms x y;
switch opcion
case 1 %Método de Euler
n=(xf-x)/h;
%clc
for i=1:n+1
y1= feval(a,x,y);
hy1=h*y1;
fprintf('\n%0.1f %0.4f ',x,y);
y=y+hy1;
x=x+h;
end
set(handles.Tresul, 'string', char(y));
case 2 %Método de Euler mejorado
case 3 %Método de Runge-Kutta
end
function Tresul_Callback(hObject, eventdata, handles)
% hObject handle to Tresul (see GCBO)

% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of Tresul as text
% str2double(get(hObject,'String')) returns contents of Tresul as a double
% --- Executes during object creation, after setting all properties.

function Tresul_CreateFcn(hObject, eventdata, handles)
% hObject handle to Tresul (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
function Txf_Callback(hObject, eventdata, handles)
% hObject handle to Txf (see GCBO)

% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of Txf as text
% str2double(get(hObject,'String')) returns contents of Txf as a double
% --- Executes during object creation, after setting all properties.
function Txf_CreateFcn(hObject, eventdata, handles)
% hObject handle to Txf (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
function Tpaso_Callback(hObject, eventdata, handles)
% hObject handle to Tpaso (see GCBO)

% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of Tpaso as text
% str2double(get(hObject,'String')) returns contents of Tpaso as a double
% --- Executes during object creation, after setting all properties.
function Tpaso_CreateFcn(hObject, eventdata, handles)
% hObject handle to Tpaso (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
% --- Executes on selection change in menuMetodo.
function menuMetodo_Callback(hObject, eventdata, handles)
% hObject handle to menuMetodo (see GCBO)

% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: contents = cellstr(get(hObject,'String')) returns menuMetodo contents as cell array
% contents{get(hObject,'Value')} returns selected item from menuMetodo
% --- Executes during object creation, after setting all properties.
function menuMetodo_CreateFcn(hObject, eventdata, handles)
% hObject handle to menuMetodo (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: popupmenu 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
function Tcond_Callback(hObject, eventdata, handles)
% hObject handle to Tcond (see GCBO)

% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of Tcond as text
% str2double(get(hObject,'String')) returns contents of Tcond as a double
% --- Executes during object creation, after setting all properties.
function Tcond_CreateFcn(hObject, eventdata, handles)
% hObject handle to Tcond (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
% --- Executes on button press in bLeer.
function bLeer_Callback(hObject, eventdata, handles)
% hObject handle to bLeer (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
function Tecua_Callback(hObject, eventdata, handles)
% hObject handle to Tecua (see GCBO)

% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of Tecua as text
% str2double(get(hObject,'String')) returns contents of Tecua as a double
% --- Executes during object creation, after setting all properties.
function Tecua_CreateFcn(hObject, eventdata, handles)
% hObject handle to Tecua (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
function Txo_Callback(hObject, eventdata, handles)
% hObject handle to Txo (see GCBO)

% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of Txo as text
% str2double(get(hObject,'String')) returns contents of Txo as a double
% --- Executes during object creation, after setting all properties.
function Txo_CreateFcn(hObject, eventdata, handles)
% hObject handle to Txo (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
function Tyo_Callback(hObject, eventdata, handles)
% hObject handle to Tyo (see GCBO)

% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of Tyo as text
% str2double(get(hObject,'String')) returns contents of Tyo as a double
% --- Executes during object creation, after setting all properties.

Best Answer

x=str2num(get(handles.Txo, 'string'));
y=str2num(get(handles.Tyo, 'string'));
Those will result in x and y being defined as numeric values (probably, but not always. str2double() would be better.)
syms x y;
Those are equivalent to
x = sym('x');
y = sym('y');
so whatever numeric values x and y had will be erased and replaced with symbolic values.
switch opcion
case 1 %Método de Euler
n=(xf-x)/h;
x is symbolic so n ends up symbolic
for i=1:n+1
with n being symbolic, 1:n+1 tries to use the : operator with a symbolic upper bound, which fails.
Related Question