I'm using datastore, but is it a correct implementation?
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Morning all,
I have two csv textfiles, each of which are over 1GB in size and contain millions of rows of data.
I would like to loop over reading the textfile and extracting relevant information based on the value of some variable in the textfile, something like:
var1 = 1:5;
var2 = 1:20;
% Setup data store
dataStore = datastore('test.csv','ReadVariableNames',true);
for i = 1:length(var1)
thisVar1 = var1(i);
for j = 1:length(var2)
thisVar2 = var2(j);
reset(dataStore);
thisData = table;
while hasdata(dataStore)
% Read in Chunk
dataChunk = read(dataStore);
thisData = [thisData
dataChunk((dataChunk.var1 == thisVar1 & dataChunk.var2 == thisvar2),:)];
end
.
.
.
end
end
This code implementation does work, but it takes an age to run and I really don't have that sort of time to sit around waiting. Can anyone help me with more efficient code or more efficient tools?
Many thanks
6 Kommentare
per isakson
am 9 Dez. 2016
Bearbeitet: per isakson
am 9 Dez. 2016
Try this with a complete file
>> cac = cssm()
cac =
{6x1 cell} [6x22 double]
>> cac{1}{1}
ans =
L_204W_204Depth_25IE_1WT_127.txt
>> cac{2}(1,1:6)
ans =
25.0000 12.7000 1.0000 20.4000 20.4000 3.0000
>>
where
function cac = cssm()
fid = fopen( 'cssm.txt' );
cac = textscan( fid, ['%s',repmat('%f',[1,22])] ...
, 'Headerlines',0, 'CollectOutput',true, 'Delimiter',',' );
[~] = fclose( fid );
end
and cssm.txt contains your six lines of data.
If you are on Windows, use the Task Manager to see how much memory is used. I assume you still have a lot of free memory.
Antworten (0)
Siehe auch
Kategorien
Mehr zu Text Files finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!