필터 지우기
필터 지우기

Matlab Invalid Data Argument

조회 수: 115 (최근 30일)
Callum Stewart
Callum Stewart 2020년 10월 16일
댓글: Callum Stewart 2020년 10월 16일
u = @(t) (t>=0);
r = @(t) t.*u;
x = @(t) r(t)-r(t-1)-3*u(t-1)-2*r(t-3)-r(t-4)-r(t-5)-u(t-7);
t = [-2:0.01:7];
plot(t,x)
Why am a getting invalid data argument as error when plotting>
[SL: formatted code as code]

답변 (2개)

Steven Lord
Steven Lord 2020년 10월 16일
Let's look at your code section by section.
u = @(t) (t>=0);
r = @(t) t.*u;
This will not work as written. You cannot multiply a number and a function handle. What you can do instead is to multiply a number and the result of evaluating a function handle.
r = @(t) t.*u(t);
In the next section there is a similar problem.
x = @(t) r(t)-r(t-1)-3*u(t-1)-2*r(t-3)-r(t-4)-r(t-5)-u(t-7);
t = [-2:0.01:7];
plot(t,x)
The plot function will not accept a function handle as its second input, but it can accept the result of evaluating a function handle.
plot(t, x(t))
  댓글 수: 1
Callum Stewart
Callum Stewart 2020년 10월 16일
Thanks this explains a lot thanks

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


Karolis Poskus
Karolis Poskus 2020년 10월 16일
Hello,
To plot anonymous function use:
doc fplot

카테고리

Help CenterFile Exchange에서 Get Started with MATLAB에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by