returning an empty array if statement

조회 수: 5 (최근 30일)
Aadam
Aadam 2011년 12월 11일
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
  댓글 수: 1
Aadam
Aadam 2011년 12월 11일
>if a or c are = 0<
sorry a and b are 0

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

답변 (2개)

Image Analyst
Image Analyst 2011년 12월 11일
if isempty(a) || isempty(c)
yourOutputArg = [];
return;
end
% else continue with the rest of your function's code.

Walter Roberson
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])

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by