我的CSV文件具有3.850.000条目。来源,目标,日期,时间例如7BC65F6F4342D49242514A50CE53D71D,5555AF6D82BBBB7F4C7475F7F7AF29E8DB147,2016-02-29,29,29,23:51:51:00
我有可能在MATLAB中绘制此CSV文件吗?我曾尝试使用Excel,但是它可以处理的大多数条目是105k ...我如何绘制日期违反时间,然后计算以下内容:a(每天拨打的电话数量b(星期一拨打的电话数等?
有人可以将我指向正确的方向吗?我什至在使用正确的工具来完成此类任务吗?谢谢!
这是一些方向和建议。
第1部分
首先,您需要读取CSV文件。以下代码应准备好用于您的应用程序。
filename = 'G:DesktopnewBook1.csv'; % specify your file name and directory
fileID = fopen(filename,'r','n','UTF-8'); % open file
try
format = '%s%s%{yyyy/MM/dd}D%{HH:mm:ss}D%[^nr]'; % format specification
data = textscan(fileID, format, 'Delimiter', ',', 'ReturnOnError', false); % read data
catch e
fclose(fileID); % close file
rethrow(e)
end
fclose(fileID); % close file
clearvars -except data % clear variables
[source, target, dateData, timeData] = data{:}; % load data
第2部分
由于已将数据加载到MATLAB中,因此您可以按日期按数据进行分组。您可以找到日期发生更改的行号:
iDate = find(diff(dateData) ~= 0); % locate where there is a change in date
iDate = [1, iDate(:)', numel(dateData)]; % add start and end
您可以使用类似的代码来查找时间。
然后您可以将数据分组:
for i = 1:numel(iDate) - 1
dataCollection{i}.date = dateData(iDate(i));
dataCollection{i}.source = source(iDate(i):iDate(i+1));
dataCollection{i}.target = target(iDate(i):iDate(i+1));
dataCollection{i}.timeData = timeData(iDate(i):iDate(i+1));
end
您可以按时间添加上述循环中的另一个循环到分组数据中。例如:
for j = 1:numel(iTime) - 1
dataCollection{i}.timeCollection{j} = dataCollection{i}.source(iTime(j):iTime(j+1));
...% more data
end
接下来,您需要计算每个日期的数据数,并在需要时计算时间。该代码可以插入现有循环中:
dataCollection{i}.dataNum = numel(dataCollection{i}.source);
dataCollection{i}.timeCollection{j}.dataNum = numel(dataCollection{i}.timeCollection{j}.source);
最后,您可以绘制曲线并替换X标签到迄今,时间或一周等。
第2部分 - 替代
浏览以上内容,您可以构建一个非常好的结构来保留数据。如果不需要,则代码可以简单得多:
iDate = find(diff(dateData) ~= 0); % locate where there is a change in date
iDate = [1, iDate(:)', numel(dateData)]; % add start and end
dataNumByDate = diff(iDate); % calculate the number of data for each date
xLabelStr = datestr(dateData(iDate(2:end))); % convert date into string for x labels
然后绘制数字。无需循环。
如果您对代码的特定部分有疑问,我建议您打开一个新问题。