MATLAB: How to use strings in function

strings

I'm inputing excel data into matlab using formula "xlsread". The variable in which I'm inputing excel data i.e "ETABSresponse" requires to have a certain size depending on size of the variable so that it will not give error "Vectors must be the same length" .
Formula for inputing data the function is of the form
ETABSresponse=xlsread('ETABS.xlsx','A1:ALM7');
But I want it to be of form so that the above problem do not occur.
ETABSresponse=xlsread('ETABS.xlsx','A1:ExcelColumn');
Where ExcelColumn is a function that converts numbers into Excel column index
it gives 'A' for 1, 'Z' for 26 and 'AA' for 27 and so on
ExcelColumn=[ExcelColumn(L/0.001+1) num2str(7)]
So if L=1 ExcelColumn(L/0.001+1) will be ALM and ExcelColumn will be 'ALM7'
I want to use second part of range as variable that can be adjusted according to my needs but the formula
ETABSresponse=xlsread('ETABS.xlsx','A1:ExcelColumn');
won't work. How can I make it work?

Best Answer

You need to concatenate the output of the function you created. That way you get a single char vector as the range specification.
ETABSresponse=xlsread('ETABS.xlsx',['A1:' ExcelColumn]);
I sometimes use a function like the one below to create the column name:
L=1;
ExcelColumn=sprintf('%s%d',get_ExcelColName(L/0.001+1),7);
disp(ExcelColumn)
ALM7
function ExcelColName=get_ExcelColName(col_val)
%convert a col value to the Excel col name (so 27 to AA, 705 to AAC)
validateattributes(col_val,{'numeric'},{'scalar','nonzero','integer'})
base=26;
col_val=col_val-1;
digs=floor(log(col_val)/log(base))+1;%number of 'digits' (i.e. letter positions)
ExcelColName=zeros(1,digs);
for cur_d=digs:-1:1
ExcelColName(cur_d)=mod(col_val,base);
col_val=(col_val-ExcelColName(cur_d))/base;
end
if isempty(ExcelColName),ExcelColName=0;end%in case of col_val input is 1
ExcelColName(end)=ExcelColName(end)+1;
ExcelColName=char(ExcelColName+64);
end