I have some code that processes experimental data of mine and saves a variable, Depth, to the workspace. I would like to include some lines that would ask the user for an input string, say NewName and use this as the name for Depth, while retaining all the data in the array. I'd rather not have to rename every instance of Depth in my code as I want to use this on other data sets and have unique names for the variable in each case.
So far I have:
prompt = 'What would you like to rename Depth?';
str = input(prompt,'s');
if (isempty(str) == 1)
str = 'Depth';
str = Depth;
so that if the input is empty, then Depth is not renamed. However, this only creates a new array str with the same values as Depth, and does not rename Depth or even create a new array, NewName, with the same values as Depth.
Is there any way to solve this or work around it?