필터 지우기
필터 지우기

undefined function 'piecewise' for input arguments of type 'double'.

조회 수: 39 (최근 30일)
Robert Pelgrift
Robert Pelgrift 2020년 2월 23일
I am trying to run the following piecewise function:
x = @(y) piecewise([y>2, 1], 0)
However, whenever I try to run it, I get the following error: "undefined function 'piecewise' for input arguments of type 'double'."
I definitely have the Symbolic Math toolbox installed and am not sure why this is happening.

답변 (1개)

Thiago Henrique Gomes Lobato
Thiago Henrique Gomes Lobato 2020년 2월 23일
piecewise defines a symbolic function, so you can't just give a double as input for the anonymous function. If you however explicitely make the substitution it will work
syms y
x = @(y) piecewise(y>2,1, 0);
subs(x,[1,2,3])
ans =
[ 0, 0, 1]
Although unless you really need it to be symbolic I would strongely recommend to remain working with numerical values:
x = @(y) double(y>2);
x([1,2,3])
ans =
0 0 1

카테고리

Help CenterFile Exchange에서 Assumptions에 대해 자세히 알아보기

태그

제품


릴리스

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by