cheching exist Variable on the IF statment

조회 수: 6 (최근 30일)
erfan vahdat
erfan vahdat 2021년 5월 3일
답변: DGM 2021년 5월 3일
How to check the exist of the one variable that does not exist in if statment.
for example we have a function that need x,y variable, and we have a equation without y in it. if i run the Function it error the missing y,,,, i want to check that if it is not exist ,GIve it some value in the IF statment and then display that y is missing beside the error of the system...
  댓글 수: 1
Adam Danz
Adam Danz 2021년 5월 3일
편집: Adam Danz 2021년 5월 3일
Do you mean the variable y is not defined or the variable y is missing from the function itself?
For example, is this the problem
x = 2;
z = x+y;
or is this the problem,
x = 2;
y = 3;
fun = @(x)x^2;
z = fun(x);
Better yet, provide a working example of what you're doing.

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

답변 (1개)

DGM
DGM 2021년 5월 3일
Something like this
if ~exist('myvariable','var')
% set default value or error or whatever
end
Although using exist() during input handling is typically slower than methods using varargin

카테고리

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

제품


릴리스

R2014b

Community Treasure Hunt

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

Start Hunting!

Translated by