Matlab: renaming workspace elements from command window? -
the gui of matlab allows me rename element in workspace right-clicking on element , selecting 'rename' option. possible command window well?
these things can test yourself, , should so. best way learn, discover.
regardless, answer no, cannot change variable name in way command window. command window keyboard input only.
edit: question apparently doing change command in command window, not done via mouse. (why not tell front?)
there no explicit command such rename. however, nothing stops writing yourself. example...
function renamevar(oldname,newname) % renames variable in base workspace % usage: renamevar oldname newname % usage: renamevar('oldname','newname') % % renamevar written used command, renaming single % variable have designated new name % % arguments: (input) % oldname - character string - must name of existing % variable in base matlab workspace. % % newname - character string - new name of variable % % example: % % change name of variable named "foo", new variable % % name "bahr". original variable named "foo" no % % longer in matlab workspace. % % foo = 1:5; % renamevar foo bahr % test errors if nargin ~= 2 error('renamevar:nargin','exactly 2 arguments required') elseif ~ischar(oldname) || ~ischar(newname) error('renamevar:characterinput','character input required - renamevar command') end teststr = ['exist(''',oldname,''',''var'')']; result = evalin('base',teststr); if result ~= 1 error('renamevar:doesnotexist', ... ['a variable named ''',oldname,''' not exist in base workspace']) end % create new variable str = [newname,' = ',oldname,';']; try evalin('base',str) catch error('renamevar:renamefailed','the rename failed') end % clear original variable str = ['clear ',oldname]; evalin('base',str)
Comments
Post a Comment