How can i use If ... else loop inside function ?

Hi, i have a problem says :
Output argument ( and maybe others) not assigned during call to " g ". Here the function of g
%% Drichlet condition : u.n=g(x,y) in the boundary
function z= g(x,y,time)
if x==0
nx=-1
ny=0
z=exp(-time).*sin(pi*x).*sin(pi*y);
end
if x==1
nx=1
ny=0
z=exp(-time).*sin(pi*x).*sin(pi*y);
end
if y==0
nx=0
ny=-1
z=exp(-time).*sin(pi*x).*sin(pi*y);
end
if y==1
nx=0
ny=1
z=exp(-time).*sin(pi*x).*sin(pi*y);
end
end

댓글 수: 1

waqas
waqas 2020년 7월 21일
What is the input that you are giving for g? Seems like you are giving both x and y at the same time and the conditions are not satisfied for if loop.

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

 채택된 답변

Fangjun Jiang
Fangjun Jiang 2020년 7월 21일

0 개 추천

If none of those conditions are met, you end up with z not assigned.
give z a default value at the begining.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

제품

릴리스

R2016b

질문:

2020년 7월 21일

답변:

2020년 7월 21일

Community Treasure Hunt

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

Start Hunting!

Translated by