Help: XLSREAD with an unpsecified number of colums

1 visualizzazione (ultimi 30 giorni)
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.

Risposta accettata

Guillaume
Guillaume il 17 Set 2014
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 Commento
Khanh
Khanh il 19 Set 2014
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?)

Accedi per commentare.

Più risposte (1)

Yona
Yona il 17 Set 2014
Modificato: Yona il 17 Set 2014
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 Commenti
Khanh
Khanh il 17 Set 2014
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 il 21 Set 2014
Modificato: Yona il 21 Set 2014
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

Accedi per commentare.

Categorie

Scopri di più su Numeric Types in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by