??? Undefined function or method 'sign' for input arguments of type 'sym'.

1 次查看(过去 30 天)
I am trying to generate a wave :
when time=0:5 then r(t)=1
when time=5:10 then r(t)=2
when time=10:15 then r(t)=1
and then I also want to take derivative of this wave (even double derivative also)
I tried it without giving t=0:15 and with syms
code:
t= 0:0.1:14.9;
aaa=sin(2*pi*0.1*t');
% %r = [1,zeros(120,1)]+2-sign(aaa);
r =2.000-sign(aaa);
size(r)
r1=diff(r,t);
size(r1)
rp=horzcat(0,r1);
size(rp)
size(t)
plot(t',rp)
------
error:when time=0:5 then r(t)=1
I also tried with if loop ,
if t>=0 && t<=5
r=1;
if t>=5 && t<=10
r=2;
if t>=10 && t<=15
r=1;
this aslo doesnot work; give some logical error message
please help

采纳的回答

Walter Roberson
Walter Roberson 2013-8-25
"when" is not a MATLAB or MuPAD command.
Your code does not use sym() or syms, so you could not be getting an error about sign of sym.
Your "t" is a vector, so "t>=0" is a vector result as is "t<=5". You cannot join vector results with "&&" as "&&" is reserved for scalars. You need to use "&" to join vector results. But you should probably read the definition of how "if" works carefully

更多回答(0 个)

Community Treasure Hunt

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

Start Hunting!

Translated by