Stuart的MATLAB视频

观察和学习

编写一个脚本来计算多个文本文件中的数据

在这里,我需要通过对一个变量进行分组和求和来组合来自多个文本文件的数据。我也试着用数据存储我以前用得不多。

本文涵盖的特性代码风格视频包括:

  • readtable,fileDatastore带读函数参数
  • varfun

跟我来(@stuartmcgarrity)如果你想在我发布的时候通过Twitter得到通知。

以全屏模式播放视频以获得更好的观看体验。

从服务器日志中读取重定向流量%%参数folderName='C:\文件夹';outputFileName =“Redirects4Weeks.csv”;获取文件列表fileInfo=dir([folderName filesep '*.csv']);文件名= {fileInfo.name} ';fullFileNames=cellfun(@(x) [folderName filesep x],fileName,'UniformOutput', false);fileDatesCell = regexp(文件名,(\ d + - \ d + \ d +)”,“令牌”);fileDatesStr = stripCell (fileDatesCell 2);fileDates = datetime (fileDatesStr);[fileDates, idx] =排序(fileDates,“下”);mostRecent4 = idx (1:4); %% Data Store fcn=@(x) readtable(x,'ReadVariableNames',false,'Delimiter',',','TextType','string', 'HeaderLines',1); ds = fileDatastore(fullFileNames(mostRecent4),'ReadFcn', fcn); cellData=readall(ds); data=vertcat(cellData{:}); data.Properties.VariableNames={'Request_URI' 'count'}; %% Count URLs pivot=varfun(@sum,data,'InputVariables','count','GroupingVariables',{'Request_URI'}); pivot.GroupCount=[]; pivot.Properties.VariableNames{'sum_count'}='count'; pivot=sortrows(pivot,{'count'},{'descend'}); %% Save writetable(pivot,outputFileName);
|

评论

如欲留言,请点击在这里登录您的MathWorks帐户或创建一个新帐户。