I've got the error Output argument "val" (and maybe others) not assigned during call to "yt". yt(x) funtion:
function [val] = yt(x)
if ((-9<=x) & (x<-3)) | ((3<=x) & (x<=9))
val = sin(5*x);
elseif (-3<=x) & (x<3)
val = cos(x) - cos(3) - sin(15);
end
and i call the function using the following
x = -9:9;
val = yt(x)
I've got no output from this.

댓글 수: 1

per isakson
per isakson 2018년 3월 10일
편집: per isakson 2018년 3월 10일

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

 채택된 답변

Ahmet Cecen
Ahmet Cecen 2018년 3월 10일
편집: Ahmet Cecen 2018년 3월 10일

1 개 추천

x is a vector at this point so your comparisons are not resolving to a single true false. I am guessing this is what you meant to do:
x = -9:9;
val = yt(x)
function [val] = yt(x)
for i = 1:length(x)
if ((-9<=x(i)) && (x(i)<-3)) || ((3<=x(i)) && (x(i)<=9))
val(i) = sin(5*x(i));
elseif (-3<=x(i)) && (x(i)<3)
val(i) = cos(x(i)) - cos(3) - sin(15);
end
end
end
There are better ways to do this of course, but this is probably the easiest to relate.

댓글 수: 1

Raul Vaida
Raul Vaida 2018년 3월 10일
Thank you very much, it worked perfectly this way!

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

추가 답변 (0개)

카테고리

도움말 센터 및 File Exchange에서 Nonlinear Dynamics에 대해 자세히 알아보기

질문:

2018년 3월 10일

댓글:

2018년 3월 10일

Community Treasure Hunt

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

Start Hunting!

Translated by