Help: XLSREAD with an unpsecified number of colums

2 visualizaciones (últimos 30 días)
Khanh
Khanh el 17 de Sept. de 2014
Editada: Yona el 21 de Sept. de 2014
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.

Respuesta aceptada

Guillaume
Guillaume el 17 de Sept. de 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 comentario
Khanh
Khanh el 19 de Sept. de 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?)

Iniciar sesión para comentar.

Más respuestas (1)

Yona
Yona el 17 de Sept. de 2014
Editada: Yona el 17 de Sept. de 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 comentarios
Khanh
Khanh el 17 de Sept. de 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 el 21 de Sept. de 2014
Editada: Yona el 21 de Sept. de 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

Iniciar sesión para comentar.

Categorías

Más información sobre Data Type Conversion en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by