필터 지우기
필터 지우기

the piecewise function runs out a weird figure

조회 수: 1 (최근 30일)
dcydhb dcydhb
dcydhb dcydhb 2019년 3월 12일
편집: Adam Danz 2022년 6월 6일
function codes are as this
function f = myfun(x)
if (x<1);
f=x.^2 ;
else
f=x;
end
end
main program codes are as this
clc;
clear all;
close all;
x=0:0.1:10;
y=myfun(x);
plot(x,y)
a simple figure but a queer figure,why
  댓글 수: 1
Adam Danz
Adam Danz 2019년 3월 12일
Hint from
doc if
"An expression is true when its result is nonempty and contains only nonzero elements (logical or real numeric)."

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

답변 (1개)

Voss
Voss 2022년 6월 3일
x=0:0.1:10;
y=myfun(x);
plot(x,y)
function f = myfun(x)
idx = x < 1;
f = zeros(size(x));
f(idx) = x(idx).^2;
f(~idx) = x(~idx);
end

카테고리

Help CenterFile Exchange에서 Specifying Target for Graphics Output에 대해 자세히 알아보기

제품


릴리스

R2014a

Community Treasure Hunt

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

Start Hunting!

Translated by