Skipping lines in datastore with read function

조회 수: 12 (최근 30일)
Fernando Meneses
Fernando Meneses 2021년 8월 3일
댓글: Fernando Meneses 2021년 8월 6일
Hello, I would like to access only to certain lines (rows) in my datastore and save them to a matrix. What I am doing now is:
1. Read all the datastore and save the data in a matrix.
2. Eliminate the data I don't want (by removing rows from the matrix).
It works, but I'm wasting a lot of time storing useless data in the first step. Is it a way to directly save the data that I want?
Information: my datastore is a collection of files, all of them with the same structure: two columns filled with numeric data. Each file has 100 rows, but I only want to save the first 60.
Thanks!

채택된 답변

Amogh Bhole
Amogh Bhole 2021년 8월 6일
As per my understanding you are interested in reading only the top 60 rows from each file. It can be done efficiently using “readcell” function.
For each file you can use the below code to read top 60 rows:
C = readcell(filename,'Range',1:60);
Then save it in the matrix.
You can refer to this link for more information.
  댓글 수: 1
Fernando Meneses
Fernando Meneses 2021년 8월 6일
Thanks Amogh!
I used this function but I had to make a small change because I had the following error with the Range:
C = readcell(filename,'Range',1:60);
ERROR:
A numeric range must be 1, 2, or 4 positive integers of the form:
[start-row, start-column, end-row, end-column], where end>=start or
[start-row, start-column] or
[start-row].
I solved it by using the Excel format:
C = readcell(filename,'Range',A1:B60);

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Spreadsheets에 대해 자세히 알아보기

제품


릴리스

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by