Help: XLSREAD with an unpsecified number of colums

2 vues (au cours des 30 derniers jours)
Khanh
Khanh le 17 Sep 2014
Modifié(e) : Yona le 21 Sep 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.

Réponse acceptée

Guillaume
Guillaume le 17 Sep 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 commentaire
Khanh
Khanh le 19 Sep 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?)

Connectez-vous pour commenter.

Plus de réponses (1)

Yona
Yona le 17 Sep 2014
Modifié(e) : Yona le 17 Sep 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 commentaires
Khanh
Khanh le 17 Sep 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 le 21 Sep 2014
Modifié(e) : Yona le 21 Sep 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

Connectez-vous pour commenter.

Catégories

En savoir plus sur Data Type Conversion dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by