필터 지우기
필터 지우기

SWITCH expression must be a scalar or string constant.

조회 수: 1 (최근 30일)
garrett schander
garrett schander 2015년 8월 12일
편집: Stephen23 2015년 8월 12일
i changed up the file a bit to see if it would run the same and im still getting errors
tspan=[0 25];
y0=[0.1;0;0.2;0];
options=odeset('mass','M(t,y)');
switch options
case ''
M1=1;
M2=1;
g=9.81;
l1=1;
l2=1;
a=M2*9.81;
b=M1*9.81;
p=zeros(4,1);
p(1)=y0(2);
p(2)=-(b+a)*sin(y0(1))+M2*l2*(y0(4)^2)*sin(y0(3)-y0(1));
p(3)=y0(4);
p(4)=-a*sin(y0(3))-M2*l1*(y0(2)^2)*sin(y0(3)-y0(1));
m=p;
case 'mass'
M1=1;
M2=1;
g=9.81;
l1=1;
l2=1;
a=[1,0,0,0];
b=[0,(M1+M2)*l1,0,M2*l2*cos(y0(3)-y0(1))];
c=[0,0,1,0];
d=[0,M2*l1*cos(y0(3)-y0(1)),0,M2*l2];
m=[a;b;c;d];
otherwise
error(['unknown flag ''' flag '''.']);
end
[t,y]=ode113(m,tspan,y0,options);
subplot(2,1,1)
plot(t,y(:,1))
grid
xlabel('Time')
ylabel('Theta1')
subplot(2,1,2)
plot(t,y(:,3))
grid
xlabel('Time')
ylabel('Theta2')
SWITCH expression must be a scalar or string constant.
Error in GSFE (line 5) switch options

답변 (2개)

the cyclist
the cyclist 2015년 8월 12일
Your variable options is a struct. A struct cannot be used in that way in a switch statement.
  댓글 수: 2
Muthu Annamalai
Muthu Annamalai 2015년 8월 12일
편집: Walter Roberson 2015년 8월 12일
Seems like the questioner is using odeset in wrong format; please refer to
Stephen23
Stephen23 2015년 8월 12일
편집: Stephen23 2015년 8월 12일
@garrett schander: In fact referring to the documentation would resolve your other question too. Although beginners seem to be allergic to reading the documentation, it does actually explain how functions and operators should be used.

댓글을 달려면 로그인하십시오.


Walter Roberson
Walter Roberson 2015년 8월 12일

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by