How its possible do define this function in Matlab?
이전 댓글 표시
Hello everyone! Im new to Matlab and i have a little problem.
I have tried to define this function like this:
function F = func(t)
time = t>=0 && t<1; F(time) = t+1;
time = t>=1 && t<2; F(time) = 0;
time = t>=2 && t<3; F(time) = 2-t;
time = t>=3; F(time) = 0;
end
But, it gives me error(picture below):

Can you help me, please
채택된 답변
추가 답변 (1개)
function g = func(t)
if t >=0 && t < 1
g = t+1 ;
elseif t >= 1 && t < 2
g = 0 ;
elseif t >= 2 && t < 3
g = 2-t ;
elseif t >= 3
g = 0 ;
end
Save the above and call it as:
g = func(0) ;
Your function should be:
function F = func(t)
time = t>=0 & t<1; F(time) = t(time)+1;
time = t>=1 & t<2; F(time) = 0;
time = t>=2 & t<3; F(time) = 2-t(time);
time = t>=3; F(time) = 0;
end
카테고리
도움말 센터 및 File Exchange에서 Code Performance에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!