ALM7 is saved as 'ALM7' in the variable ExcelColumn in Workspace section of Matlab. Maybe the problem is with single quotes around ALM7? If it is then how can I resolve that?
How to use strings in function
11 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Osama Anwar
am 1 Jan. 2021
Kommentiert: Osama Anwar
am 1 Jan. 2021
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?
2 Kommentare
Akzeptierte Antwort
Rik
am 1 Jan. 2021
Bearbeitet: Rik
am 1 Jan. 2021
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)
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
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Data Type Conversion finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!