returning an empty array if statement
21 次查看(过去 30 天)
显示 更早的评论
Hi there I am kinda new to programming.
I am attempting to solve a question which is checking if 2 fields are empty and if they are return an empty array:
for example if I wanted to calculate the third side of a tiangle as long as a and b were present i could calculate c. if a or c are = 0 then I would need to return an empty array. so far I have:
if a && b == 0
not much I know but its a start haha
回答(2 个)
Image Analyst
2011-12-11
if isempty(a) || isempty(c)
yourOutputArg = [];
return;
end
% else continue with the rest of your function's code.
0 个评论
Walter Roberson
2011-12-11
Looks like Aadam doesn't really mean "empty" for a and b.
if a == 0 || b == 0
This could also be coded as
if any([a,b]==0)
or, more obscurely,
if ~all([a,b])
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!