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
조회 수: 1 (최근 30일)
이전 댓글 표시
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?
채택된 답변
Rik
2021년 1월 1일
편집: Rik
2021년 1월 1일
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
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Downloads에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!