The who function returns the names of variables in matlab. It also has a built-in regexp for selecting certain items:
X10_May_data = [1 2 3];
save X10_May_data.mat X10_May_data
clear
load X10_May_data.mat
w = who('-regexp','X*')
w =
'X10_May_data'
You can then operate on w{1} to do any substitutions you want. For example, use the strrep function for simple modifications of a string:
newvar = strrep(w{1},'May','latest')
newvar =
X10_latest_data
For more complex modifications, use regexp or regexprep. When you have the new name, you can assign it with eval:
eval([newvar '=' w{1}]) % like typing "X10_latest_data = X10_May_data"
X10_latest_data =
1 2 3
[edit] PS I agree with the comments that eval is usually a bad idea; but sometimes you just need to get something done :) For alternative approaches, see the matlab page on the topic.
'10-May-data.dat'created? Withsave? Is it actually a MAT-file despite the extension?s = load('10-May-data.dat')return? Or are you just trying to dofname = '10-May-data.dat';str = strsplit(fname,{'-','.'});vname = ['X' strjoin(str(1:end-1),'_')]?load