Help: XLSREAD with an unpsecified number of colums

조회 수: 2 (최근 30일)
Khanh
Khanh 2014년 9월 17일
편집: Yona 2014년 9월 21일
Hi
Instead of using xlsread(filename, -1) to choose interactively any region of data, how could I use the following function with a variable of colum?
inputdata=xlsread('c:\thm.xlsx','sheet1','a1:letter(x)')
Where, "letter" and "x" are colum variables. "letter" variable may be B, C, D, E, F or whatever. And "x" may be 1, 2, 3, 4 or whatever. They are not specified and depend on users. Are there any ways to execute the above function?
Khanh.

채택된 답변

Guillaume
Guillaume 2014년 9월 17일
If you also want columns:
range = sprintf('%c%d', column+64, row);
This will only work up to column Z, after that you'll have to write a function to do the conversion, it's going to be something like:
if column <= 27 %one letter
colletters = char(column + 64)
elseif column <= 27*28 %two letters
column = column - 28;
colletters = sprintf('%c%c', floor(column/27)+65, mod(column, 27)+65);
elseif ... %for three letters
  댓글 수: 1
Khanh
Khanh 2014년 9월 19일
Hi Guillaume, Are there anyways to read data with the letter out of the number of the letters (from a to z)? For example, instead of using xlsread(filename, -1), how can I read data at aa1 colum (next to right of z1 colum?)

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Yona
Yona 2014년 9월 17일
편집: Yona 2014년 9월 17일
you can defined it in string.
for example if you have 4:
N=4;
st = ['A1:E' num2str(N)];
inputdata=xlsread('c:\thm.xlsx','sheet1',st)
you can replace the second line by:
st = strcat('A1:E', num2str(N))
  댓글 수: 3
Khanh
Khanh 2014년 9월 17일
Thanks all. One more thing I forgot to add to my post, although I edited it.
How about the letter precedes with the number? For example: B1, B2, B3... C1, C2, C3..., D1, D2, D3...etc
Yona
Yona 2014년 9월 21일
편집: Yona 2014년 9월 21일
it the same thing with letter you just dont need to transform it to string. if you get it in col
N=4;
col = 'B';
st = strcat('A1:', col, num2str(N));
it will give you A1:B4

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Data Type Conversion에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by