How can i use If ... else loop inside function ?
5 次查看(过去 30 天)
显示 更早的评论
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
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
2020-7-21
If none of those conditions are met, you end up with z not assigned.
give z a default value at the begining.
0 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Loops and Conditional Statements 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!