Does EXIST work in GUIDE (GUI)

12 次查看(过去 30 天)
Lex
Lex 2011-7-11
Hello, I have a little problem with EXIST function. I'm having a button with some calculations in code but later in code there is modification button(that asignin to workspace some other values). I've tride simple IF function (if exist modified value in workspace then do something else). But It does not work
if exist('N1pg','var')==0
....
else
...
end
if(get(handles.radiobutton10,'Value'))== (get(handles.radiobutton10,'Max'))
N1pg=str2num(get(handles.edit86,'String'));
assignin('base','N1pg',N1pg);
Thank you for solution\fix.

采纳的回答

Jan
Jan 2011-7-11
EXIST checks the existence in the workspace of the current function. ASSIGNIN('base', ...) assigns the variable in the base workspace. Therefore EXIST cannot see the variable.
Creating variables in another workspace is a frequent source of problems. It is more stable to create the variables locally in the GUI (see GUIDATA, UserData, ApplicationData) and use a dedicated function to export them on demand only.

更多回答(3 个)

Paulo Silva
Paulo Silva 2011-7-11
Inside your GUI or any function:
e=evalin('base','who'); %get all the variables names present in the workspace
if ismember('N1pg',e) %check if your variable is one of them
%is one of them, do something
else
%the variable isn't in the workspace yet, do something else
end

Lex
Lex 2011-7-11
Oh thank you. I'll try to use GUIDATA. And let you know if I succeeded :)

Lex
Lex 2011-7-11
"Thank IOU" Paulo your sollution works perfect!

类别

Help CenterFile Exchange 中查找有关 Whos 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by