あなたのファイルには、大きなファイルを扱うため、このツールをデータストア
https://es.mathworks.com/help/matlab/import_export/what-is-a-datastore.html
との良好な実装を持っているMATLABのための大きなCSVのように見え、があります。
https://es.mathworks.com/help/matlab/large-files-and-big-data.html
また、働くことを見てくださいwith tables in matlab
私は例えばので、テーブルなどのデータで作業し、必要な変数を取得することができ、データストアTOUで
サンプルファイルairlinessmall.csv(123524行)
Year,Month,DayofMonth,DayOfWeek,DepTime,CRSDepTime,ArrTime,CRSArrTime,UniqueCarrier,FlightNum,TailNum,ActualElapsedTime,CRSElapsedTime,AirTime,ArrDelay,DepDelay,Origin,Dest,Distance,TaxiIn,TaxiOut,Cancelled,CancellationCode,Diverted,CarrierDelay,WeatherDelay,NASDelay,SecurityDelay,LateAircraftDelay
1987,10,21,3,642,630,735,727,PS,1503,NA,53,57,NA,8,12,LAX,SJC,308,NA,NA,0,NA,0,NA,NA,NA,NA,NA
1987,10,26,1,1021,1020,1124,1116,PS,1550,NA,63,56,NA,8,1,SJC,BUR,296,NA,NA,0,NA,0,NA,NA,NA,NA,NA
1987,10,23,5,2055,2035,2218,2157,PS,1589,NA,83,82,NA,21,20,SAN,SMF,480,NA,NA,0,NA,0,NA,NA,NA,NA,NA
1987,10,23,5,1332,1320,1431,1418,PS,1655,NA,59,58,NA,13,12,BUR,SJC,296,NA,NA,0,NA,0,NA,NA,NA,NA,NA
1987,10,22,4,629,630,746,742,PS,1702,NA,77,72,NA,4,-1,SMF,LAX,373,NA,NA,0,NA,0,NA,NA,NA,NA,NA
1987,10,28,3,1446,1343,1547,1448,PS,1729,NA,61,65,NA,59,63,LAX,SJC,308,NA,NA,0,NA,0,NA,NA,NA,NA,NA
1987,10,8,4,928,930,1052,1049,PS,1763,NA,84,79,NA,3,-2,SAN,SFO,447,NA,NA,0,NA,0,NA,NA,NA,NA,NA
1987,10,10,6,859,900,1134,1123,PS,1800,NA,155,143,NA,11,-1,SEA,LAX,954,NA,NA,0,NA,0,NA,NA,NA,NA,NA
...
:ウル場合は、あなたがこのような何かを働かせることができます到着遅延の平均を取得する:
>> ds = datastore('airlinesmall.csv','TreatAsMissing','NA');
>> ds.MissingValue = 0;
>> ds.SelectedVariableNames = 'ArrDelay';
>> data = preview(ds)
data =
ArrDelay
________
8
8
21
13
4
59
3
11
>> data % this is a table
data =
ArrDelay
________
8
8
21
13
4
59
3
11
>> sums = [];
counts = [];
while hasdata(ds)
T = read(ds); % this is a table, but this is not all loaded in memory
sums(end+1) = sum(T.ArrDelay);
counts(end+1) = length(T.ArrDelay);
end
>> avgArrivalDelay = sum(sums)/sum(counts)
avgArrivalDelay =
6.9670
あなたのサンプルで作業してみましょう。 2日毎にのは、これを見てみましょう
sample.csvあなたはその失敗1は見ることができます
TYPE OF FAILURE, START DATE, START TIME, DURATION, LOCALIZATION, WORKING TEAM, SHIFT
failure 1, 06/01/2017, 12/13/20, 300, Area 1, A, morning
failure 2, 06/01/2017, 12/13/20, 300, Area 1, A, night
failure 3, 06/01/2017, 12/13/20, 400, Area 1, A, afternoon
failure 1, 08/01/2017, 12/13/20, 300, Area 1, A, morning
failure 2, 09/01/2017, 12/13/20, 300, Area 1, A, morning
failure 3, 09/01/2017, 12/13/20, 300, Area 1, A, night
failure 3, 09/01/2017, 14/13/20, 200, Area 1, A, morning
failure 1, 10/01/2017, 12/13/20, 300, Area 1, A, morning
failure 1, 12/01/2017, 12/13/20, 300, Area 1, A, afternoon
failure 2, 12/01/2017, 12/13/20, 500, Area 1, A, morning
failure 1, 14/01/2017, 12/13/20, 300, Area 1, A, night
:このファイルをチェック
>> ds = tabularTextDatastore('sample.csv')
Warning: Variable names were modified to make them valid MATLAB identifiers.
ds =
TabularTextDatastore with properties:
Files: {
'/home/anquegi/learn/matlab/stackoverflow/sample.csv'
}
FileEncoding: 'UTF-8'
ReadVariableNames: true
VariableNames: {'TYPEOFFAILURE', 'STARTDATE', 'STARTTIME' ... and 4 more}
Text Format Properties:
NumHeaderLines: 0
Delimiter: ','
RowDelimiter: '\r\n'
TreatAsMissing: ''
MissingValue: NaN
Advanced Text Format Properties:
TextscanFormats: {'%q', '%q', '%q' ... and 4 more}
ExponentCharacters: 'eEdD'
CommentStyle: ''
Whitespace: ' \b\t'
MultipleDelimitersAsOne: false
Properties that control the table returned by preview, read, readall:
SelectedVariableNames: {'TYPEOFFAILURE', 'STARTDATE', 'STARTTIME' ... and 4 more}
SelectedFormats: {'%q', '%q', '%q' ... and 4 more}
ReadSize: 20000 rows
>> ds.SelectedVariableNames = {'TYPEOFFAILURE', 'STARTDATE', 'STARTTIME', 'DURATION', 'LOCALIZATION', 'WORKINGTEAM', 'SHIFT'}
ds =
TabularTextDatastore with properties:
Files: {
'/home/anquegi/learn/matlab/stackoverflow/sample.csv'
}
FileEncoding: 'UTF-8'
ReadVariableNames: true
VariableNames: {'TYPEOFFAILURE', 'STARTDATE', 'STARTTIME' ... and 4 more}
Text Format Properties:
NumHeaderLines: 0
Delimiter: ','
RowDelimiter: '\r\n'
TreatAsMissing: ''
MissingValue: NaN
Advanced Text Format Properties:
TextscanFormats: {'%q', '%q', '%q' ... and 4 more}
ExponentCharacters: 'eEdD'
CommentStyle: ''
Whitespace: ' \b\t'
MultipleDelimitersAsOne: false
Properties that control the table returned by preview, read, readall:
SelectedVariableNames: {'TYPEOFFAILURE', 'STARTDATE', 'STARTTIME' ... and 4 more}
SelectedFormats: {'%q', '%q', '%q' ... and 4 more}
ReadSize: 20000 rows
>> reset(ds)
accum = [];
while hasdata(ds)
T = read(ds);
accum = datetime(T(strcmp(T.TYPEOFFAILURE,'failure 1'),:).STARTDATE, 'InputFormat','dd/MM/yyyy');
mean(diff(accum))
end
ans =
48:00:00
%ちょうど48時間ごとに、次にあなたが試すことができますあなたが望むすべてのもので
ありがとうございました。 Matlabのデータストアを見ていきます。しかし私は、私の質問のアルゴリズム的な部分を解決するためにも探していました。それについて何か教えてもらえますか?:) –
もちろん、サンプルファイル、5-6行、そのファイルに適用されたサンプルを貼り付けることができます。 – anquegi
upvoteまたはgift vcorrectの答えを忘れないように役立つ場合は、サンプルデータを扱うように編集しました – anquegi