Who can help me with this please?

1 view (last 30 days)
Andrés Felipe
Andrés Felipe on 13 May 2015
Commented: Walter Roberson on 13 May 2015
I have this code
function radiobutton4_Callback(hObject, eventdata, handles)
a=handles.edit5;
%a=3;
f=handles.edit2;
r1=handles.edit7;
r2=handles.edit8;
c=handles.edit9;
w=2*pi*f;
x=0:0.01:2*f;
syms x
y=a*sin((w*x));
Y=int(y,x);
z=(-1/(r1*c)).*Y
%z=(-r2/r1)*a*sin(w*x).*(1-exp(-x/(r2*c)));
%z=2*sin(2*pi/f*x+0);
axes(handles.axes2)
plot(x,y,x,double(z),'g')
grid on
And i need to graphic x,y and x,z in the same plot, but i got this error
Error using mupadmex
Error in MuPAD command: DOUBLE cannot convert the input expression into a double array.
If the input expression contains a symbolic variable, use the VPA function instead.
Error in sym/double (line 514)
Xstr = mupadmex('symobj::double', S.s, 0);
Error in proyectoanaloga2>radiobutton4_Callback (line 219)
plot(x,y,x,double(z),'g')
Error in gui_mainfcn (line 96)
feval(varargin{:});
Error in proyectoanaloga2 (line 42)
gui_mainfcn(gui_State, varargin{:});
Error in
@(hObject,eventdata)proyectoanaloga2('radiobutton4_Callback',hObject,eventdata,guidata(hObject))
Error using figure
Error while evaluating uicontrol Callback

Answers (1)

Walter Roberson
Walter Roberson on 13 May 2015
Your y is symbolic because it uses syms x. Your Y is symbolic because indefinite integration of y with respect to x gives a symbolic formula. Your z is a formula in that symbolic Y.
Your plot has plot(x,y,x,double(z)) which tries to construct two lines, one x vs y and the other x vs double(z). But all of those, x, y, and z, are symbolic with a free variable. They cannot be converted to numeric form to plot.
In order to do any plotting, you need to have definite values to evaluate at, and evaluate the symbolic expressions at those values.
You did have
x=0:0.01:2*f;
which looks at first like it provides definite values to x, but on the very next line you have
syms x
and that is equivalent to
x = sym('x');
complete with the implication of overwriting any existing value of x.
So... what you need is when you want to plot,
xn = 0:0.01:2*f;
yn = subs(y, x, xn);
zn = subs(z, x, xn);
plot(xn, yn, xn, zn, 'g');
  3 Comments
Andrés Felipe
Andrés Felipe on 13 May 2015
I think is working now, I have a problem with the sawtooth function instead sin, it gives me this error
Error using proyectoanaloga2>radiobutton5_Callback (line 254) Input arguments must be 'double'.
Error in gui_mainfcn (line 96) feval(varargin{:});
Error in proyectoanaloga2 (line 42) gui_mainfcn(gui_State, varargin{:});
Error in @(hObject,eventdata)proyectoanaloga2('radiobutton5_Callback',hObject,eventdata,guidata(hObject))
Error while evaluating uicontrol Callback
Walter Roberson
Walter Roberson on 13 May 2015
I need to see the code inside the callback function.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!