Asked by Francisco Molina
on 19 Oct 2019 at 19:12

I have a problem, when I try to plot any function, for Example this:

%pendulum1.m Solves y"+w^2*sin(y), y=theta, y0=10 degrees, y'(0)=0.

close all;

clear all;

clc;

g=9.81;

L=1;%SI standard units

w=sqrt(g/L); %rad/s

f=w/2/pi; % Hz

T=1/f; % period in seconds

tspan=[0 2]; y0=[85 0];%degrees

y0=(pi/180)*y0;%radians

pendulum= @(t,y) [y(2); -w^2*sin(y(1))];

[t,y] = ode45(pendulum,tspan, y0);

y=y*180/pi;%degrees

plot(t,y(:,1),'lineWidth',2.5);

xlabel('t'); ylabel('y_{1}(t), degrees');title('\theta (t)');grid

figure;

plot(y(:,1),y(:,2),'linewidth',2); xlabel('\theta (t)');grid on;

ylabel('d \theta / dt (t)');

I have this warnings and errors:

Undefined operator '/' for input arguments of type 'meta.class'.

Error in handle (line 3)

X = [y ? width/2, y+width/2, y+width/2, y ? width/2];

Error in claNotify

Error in cla (line 42)

claNotify(ax,extra{:});

Error in newplot>ObserveAxesNextPlot (line 152)

cla(ax, 'reset', hsave);

Error in newplot (line 93)

ax = ObserveAxesNextPlot(ax, hsave);

Error in matlab.graphics.internal.newplotwrapper (line 12)

axReturn = newplot(varargin{:});

Error in pendulolibro (line 15)

plot(t,y(:,1),'lineWidth',2.5);

The function Handle has the next code:

function handleip...

= drawBase(y, width, height, gap, handle, mode)

X = [y ? width/2, y+width/2, y+width/2, y ? width/2];

Y = [gap, gap, gap+height, gap+height];

if isempty(handle),

handleip = fill(X,Y,'m','EraseMode', mode);

else

set(handle,'XData',X,'YData',Y);

end

I need help and I hope someone can help me with this problem. Regards.

Answer by Adam Danz
on 19 Oct 2019 at 19:23

Edited by Adam Danz
on 19 Oct 2019 at 21:16

________________________________________________

?

Name: Question mark

Uses: Metaclass for MATLAB class

Description: The question mark retrieves the meta.class object for a particular class name. The ? operator works only with a class name, not an object.

Examples

Retrieve the meta.class object for class inputParser:

?inputParser

More Information

____________________________________________________

In your code, this line below is not proper Matlab syntax.

% v v

X = [y ? width/2, y+width/2, y+width/2, y ? width/2];

Sign in to comment.

Answer by Star Strider
on 19 Oct 2019 at 20:50

Although I usually suggest that images of code are inappropriate, that might be a way to figure out what is wrong with this line:

X = [y ? width/2, y+width/2, y+width/2, y ? width/2];

since it is likely that the ‘?’ are actually Unicode characters that the MATLAB editor cannot deal with, and so replaces them with ‘?’. You need to use ASCII code operators only with MATLAB.

Sign in to comment.

Answer by Steven Lord
on 20 Oct 2019 at 0:08

Sign in to comment.

Opportunities for recent engineering grads.

Apply Today
## 1 Comment

## Adam Danz (view profile)

## Direct link to this comment

https://ww2.mathworks.cn/matlabcentral/answers/486317-ploting-problems-with-handle-maybe-i-have-changes-in-this-function#comment_758239

Sign in to comment.