How to read only first/last column from a .dat file to make faster the code

2 ビュー (過去 30 日間)
Nisat Nowroz Anika
Nisat Nowroz Anika 2015 年 4 月 27 日
回答済み: Ingrid 2015 年 4 月 27 日
Hi all,
I'm doing some simulation using in house code where I simulate the channel flow for various Reynolds number. As a results, I have huge number of data files (.dat) for each time step.
But for post processing, I want to read only the first column using matlab. To do that, I was used "load" function and read the first column again I need to unload that file. But I observed that, when I used 'load" function it took long time for loading and unloading the data.
So at this stage, to make my matlab code faster I want to read only the first column without loading the full .dat file.
Notice that, the sequence of each .dat file is float float float
Can anybody pls. tell me about the procedure.
Thanks.
Cheers!
Anika
P.S. case_file.csv is attached

回答 (1 件)

Ingrid
Ingrid 2015 年 4 月 27 日
why don't you use textscan? See code below. Couldn't test if it is faster or not since the data is not attached
fid = fopen('case_file.csv');
firstColumn = textscan(fid,'%f%*f%*f);
fclose(fid);

カテゴリ

Help Center および File ExchangeAnnotations についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by