Extract the certain rows from a tall array

2 次查看(过去 30 天)
I am working on a text file with 22 GB consisting of around 180 million rows and 17 columns. I want to extract the specific raws (e.g. 3rd to 100th row, and only the 2nd column) and put it in memory (i.e. gather) instead of leaving it as unevaluated data.
data='D:\...\SQLDataExport.txt';
ds = tabularTextDatastore(data);
t_array=tall(ds);
trip=gather(t_array(2:100,2:2));
This would take much longer than I expected. A wierd thing is that if I extract data from the beginning (e.g. 1st row to 100th row, and only the 2nd column). It takes much much shorter time to complete.
data='D:\...\SQLDataExport.txt';
ds = tabularTextDatastore(data);
t_array=tall(ds);
trip=gather(t_array(1:100,2:2));
From my understanding, they both put a matrix about 100 by 1 into memory. Why would the first take much much longer than the second?

回答(1 个)

Rajani Mishra
Rajani Mishra 2019-7-19
Hi,
I think the difference between the time taken for rows 1:100 and 2:100 can be because for rows between 1 to 100, just first 100 rows are extracted. For rows between any N:M full numeric indexing algorithm is used. A lot more work is done as numeric indexing is geared up for tall index which in turn causing the delay.
You can try using head for speeding up, like this:
trip=gather(head(t_array(2:100,2:2),99));

类别

Help CenterFile Exchange 中查找有关 Tall Arrays 的更多信息

产品


版本

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by