How to define range using a variable in xlsread?

20 ビュー (過去 30 日間)
Rishabh Mittal
Rishabh Mittal 2019 年 9 月 25 日
コメント済み: Rishabh Mittal 2019 年 9 月 27 日
I would like to read a row from excel file in Matlab. The row's staring and end columns are defined but I would like to use a variable to define the row number. I have tried the following:
row_no = 50;
x = xlsread('yourfile.xlsx', 'sheet', ['B50:EHI' num2str(row_no)]);
The above code allows the use of variable `row_no` to define the end cell `EHI50`. But can this also be done for referring to the starting cell `B50`?

採用された回答

Adam
Adam 2019 年 9 月 25 日
編集済み: Adam 2019 年 9 月 25 日
doc sprintf
can create a string out of variables, e.g.
columnStr = 'B';
startRow = 50;
endRow = 50;
sprintf( '%s%i:EHI%i', columnStr, startRow, endRow )
Or if you always want the same start and end row you can simplify it by using the same variable for both.
  1 件のコメント
Rishabh Mittal
Rishabh Mittal 2019 年 9 月 27 日
Thanks Adam for your answer. I also found an alternate solution:
['B' num2str(row_no) ':EHI' num2str(row_no)];
Both of the solutions work.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeSpreadsheets についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by