I'm trying to create a function and it's not working, I don't know what's wrong with it?
조회 수: 2 (최근 30일)
이전 댓글 표시
function gx = g(x)
x1 = find(x <-pi);
gx(x1)=-1;
x2 = find(x>=-pi & x<=pi);
xs = x(x2);
gx(x2)=cos(xs);
x3 = find(x>pi);
gx(x3)=-1;
end
x=-2.*pi;0.01;2.*pi;
gx=g(x)
plot (x,gx)
댓글 수: 0
답변 (1개)
the cyclist
2021년 10월 29일
You need
x=-2.*pi:0.01:2.*pi;
instead of using semicolons for defining the vector.
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Matrix Indexing에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!