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 CenterFile Exchange에서 Spreadsheets에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by