cheching exist Variable on the IF statment

6 vues (au cours des 30 derniers jours)
erfan vahdat
erfan vahdat le 3 Mai 2021
Réponse apportée : DGM le 3 Mai 2021
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 commentaire
Adam Danz
Adam Danz le 3 Mai 2021
Modifié(e) : Adam Danz le 3 Mai 2021
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.

Connectez-vous pour commenter.

Réponses (1)

DGM
DGM le 3 Mai 2021
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

Catégories

En savoir plus sur Programming dans Help Center et File Exchange

Produits


Version

R2014b

Community Treasure Hunt

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

Start Hunting!

Translated by