how to check whether the variable is present or not ?

2 ビュー (過去 30 日間)
Manoj Kumar
Manoj Kumar 2014 年 12 月 9 日
回答済み: Mohammad Abouali 2014 年 12 月 9 日
hi, I have tried if condition with the help of "exist" as:
checkVariable1= exist('lbl_edge','var');
if checkVariable1==1
edge= newedge1;
else
edge = newedge2;
end
I have also tried
if any(strcmp(who,'lbl_edge'))==1
....
else
...
end
But none of them are working. Can you please help me...
Thanks

採用された回答

Mohammad Abouali
Mohammad Abouali 2014 年 12 月 9 日
Works on mine. Try this code.
clear;clc;close all
checkVariable1= exist('lbl_edge','var');
if checkVariable1==1
disp('Exist')
else
disp('didn''t exist')
end
disp('now creating the variable.')
lbl_edge='something';
checkVariable1= exist('lbl_edge','var');
if checkVariable1==1
disp('Exist')
else
disp('didn''t exist')
end
Gives this output
didn't exist
now creating the variable.
Exist

その他の回答 (1 件)

Image Analyst
Image Analyst 2014 年 12 月 9 日
checkVariable1= exist('lbl_edge','var');
will work. Perhaps you have the Image Processing Toolbox and have conflict between your variable name of edge and the IPT function called edge(). Pick a different name.

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by