How to access specific rows (or columns) of a file data without loading all data?

I try to find a good way in accessing specific rows (or columns) in a large data file (either .csv, .mat, or .txt file) without loading the entire data (e.g., data are double). Using matfile allows me just to access blocks or equally spaced intervals and I cannot figure out how to do this with datastore. Would be great if anyone knows a solution. Thanks.

Answers (1)

If you're using a .mat file and 'rows (or columns)' refer to an array stored in that file, then the doc helps: load-parts-of-variables-from-mat-files

5 Comments

Thanks for the hint. However, it does not resolve the problem. Here an example:
D = matfile('myData.mat')
Assume a matrix A exist in myData.mat. Then
subA = D.A(1:10,:)
subA = D.A(1:2:10,:)
will work. However,
subA = D.A([1 2 10],:)
will not work and thats how I would like to access A. I am grateful for ideas.
In what sense does the last example not work? Does it not assign values to subA?
This is the error you will get:
Cannot index into 'A' because ranges for MatFile objects must increase in equally spaced intervals.
I would like to randomly (or certain chunks not necessarily equally spaced) select rows or columns of a matrix (or .csv table).
Fair enough. The Doc also specifies the indices need to be equally spaced. Is there a chance you can maybe loop through the indices?
That would be a solution. However, it would access the file many times and for big files that is prohibitive.

Sign in to comment.

Categories

Asked:

on 16 Nov 2016

Commented:

on 18 Nov 2016

Community Treasure Hunt

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

Start Hunting!