MATLAB: How to properly convert variable names into a chain of strings in Matlab

dataMATLABsavestringstringsvariables

I'm using the save command to store useful data of certain variables a, b_123, cc42,…. I want to have the variable names converted to something like a chain form of 'a','b_123','c42',…: chain(a,b_123,cc42,…)
so that instead of manually writing:
save(file,'a','b_123','cc42',...);
I can simply write:
save(file,chain(a,b_123,cc42,...));
Now that way if for example I want to change the name of cc42 to say cc43 (and using shift+enter to change it in all locations) I won't need to manually change it in the save command from 'cc42' to 'cc43'.

Best Answer

If you use number in variable name then you'll run into trouble soon or later. Just don't do it.
Not sure the advantage of using variable it-self rather typing the name directly, beside that the name might change, but then how do you know the right variable after reading back the file ?
a = 1;
b = 2;
s = chain(a,b);
save('myfile.mat', s{:});
function s = chain(varargin)
s = cell(1,nargin);
for k=1:nargin
s{k} = inputname(k);
end