Help: XLSREAD with an unpsecified number of colums

1 回表示 (過去 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 Center および File ExchangeNumeric Types についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by