Python-like generator for reading large CSV file?

6 ビュー (過去 30 日間)
roudan
roudan 2018 年 4 月 16 日
回答済み: roudan 2018 年 4 月 16 日
I have a large csv file, typically I just read everything into a array like this
num =csvread(filename,2,2)
if csv file is big, the num array will be big as well and sometime it blowout my memory.
In python, there is a way to read the file but without holding the data in the memory. the methods use generator object. For example,
Base case(w/o using generator object):
value=[len(x) for x in open('filename.tx')] this case will hold the data in the memory
another case(use generator object:
it=(len(x) for x in open('filename.tx'))
the it is a generator object and it only hold the memory size for the generator expression without holding memory for all the data, later, we just extract the data by using next(it).
I am wondering if Matlab has similar generator object as Python when reading csv file to save the memory? Thanks

採用された回答

Guillaume
Guillaume 2018 年 4 月 16 日

その他の回答 (1 件)

roudan
roudan 2018 年 4 月 16 日
Thank you, Guillaume. That is awesome! I appreciate it.

カテゴリ

Help Center および File ExchangeCall Python from MATLAB についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by