"Undefined function or variable" in GUIDE

2 visualizaciones (últimos 30 días)
Gheorghe Madalina Eleonora
Gheorghe Madalina Eleonora el 14 de Sept. de 2017
Comentada: Walter Roberson el 14 de Sept. de 2017
I have a script who replace some values. The problem is that when i click the action button for firt time, it work, but second give me this error :
Undefined function or variable 'redenumire'.
Error in
matlab.graphics.internal.figfile.FigFile/read>@(hObject,eventdata)redenumire('renamebtn_Callback',hObject,eventdata,guidata(hObject))
How can i solve this ? I'm totally at the start with Matlab, and i can't find a response for my question on internet.

Respuestas (1)

Walter Roberson
Walter Roberson el 14 de Sept. de 2017
You code might be cd'ing (changing directory) away from the directory that holds the .m file for your code.
  2 comentarios
Gheorghe Madalina Eleonora
Gheorghe Madalina Eleonora el 14 de Sept. de 2017
i have only one cd... This is the function
function renamebtn_Callback(hObject, eventdata, handles)
dir=get(handles.directorytext,'String');
if ~strcmp(dir,'')
PathName=handles.PathName;
calea=handles.PathName;
cd(calea)
client=handles.client;
new_name=get(handles.newname,'String');
old_name=get(handles.oldname,'String');
warndlg('Operation complete!')
else
warndlg('Choose directory')
end
Walter Roberson
Walter Roberson el 14 de Sept. de 2017
Right. You cd to calea but you do not cd back. After the first cd, your script redenumire.m is no longer in your current directory and MATLAB cannot find it to execute the code.
  • avoiding cd is generally more robust
  • if you do cd then do so only in the context of
olddir = pwd;
try
cd(newdir)
...
catch
end
cd(olddir)
Even that is risky as it cannot handle running out of memory or the user using control-C

Iniciar sesión para comentar.

Categorías

Más información sobre File Operations en Help Center y File Exchange.

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by