Hi Mikkel,
I do not know which data from the sheet you want to assign to the variable, but lets suppose you already have your data in this variable:
Now you can follow this steps:
- Read the name on the sheet and modify it to fit the variable names restrictions:
[~,~,name] = xlsread('Test.xls',1,'A13');
name_split = strsplit(name{1},'-');
new_name = strcat(name_split(1),'_',name_split(2));
At this point you will have 'PP_217' instead of 'PP-217'.
- Generate a new variable with that name, and assign the value in your data variable:
var_name = genvarname(new_name);
eval([var_name '= var_data;']);
Now you will have what you are looking for.
Note that you can change 'var_data' with a command (i.e. if you want to read a matrix from the excel sheet). Also note that genvarname can be deprecated in your Matlab version, but there are replacements for the function.
I hope this helps!
Angel.
Best Answer