Increment cell number in xlsread

조회 수: 8 (최근 30일)
Christo van Rensburg
Christo van Rensburg 2019년 10월 17일
편집: Adam Danz 2019년 10월 21일
Hi
I'm reading values from a excel spreadsheet with xlsread as such:
exp.Vc = xlsread('BD.xlsx', 1, 'E9');
and was wondering if it is at all possible to increment the cell number I'm reading the data from?
Thanks in advance!
  댓글 수: 2
Bob Thompson
Bob Thompson 2019년 10월 17일
What do you mean by 'increment'? Are you looking to capture multiple cells at once over a range, something like every fifth cell in column E?
xlsread is a nice command, but every time you use it you have to open and close excel. If you are looking to read multiple values from the same excel sheet, I recommend reading the entire range you want first, and then indexing your way through the variable in matlab directly.
Christo van Rensburg
Christo van Rensburg 2019년 10월 17일
So in my original question I read data from cell 'E5'. I want that to increase to cell 'E6' after I've run the program once and so on.

댓글을 달려면 로그인하십시오.

답변 (1개)

Adam Danz
Adam Danz 2019년 10월 17일
편집: Adam Danz 2019년 10월 21일
Create the range value using sprintf() where you can specify both the column and row values. Then you can control the row number within a loop or just by providing a new row number.
col = 'E';
row = 7;
exp.Vc = xlsread('BD.xlsx', 1, sprintf('%s%d',col,row));
Alternatively, you can just read in all of the data at once and then using indexing to increment through those values.

카테고리

Help CenterFile Exchange에서 Data Import from MATLAB에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by