다음은 몇 가지 지침과 제안 사항입니다.
1
첫 번째 부분, 당신은 csv 파일을 읽을 필요가있다. 다음 코드는 응용 프로그램에 사용할 준비가되어야합니다.
filename = 'G:\Desktop\new\Book1.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%[^\n\r]'; % 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
부분이 matlab에에 데이터를로드 한 이후 2
, 당신은 날짜별로 그룹에 데이터를 시작할 수 있습니다. 날짜 변경이 발생하는 위치 당신은 줄 번호를 찾을 수 있습니다
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);
마지막으로, 당신은 등
2 부, 당신의 곡선을 그릴과 날짜, 시간 또는 일주일에 X 라벨을 교체 할 수 있습니다 - 대체
위를 살펴보면 데이터를 보관할 수있는 매우 멋진 구조를 만들 수 있습니다. 이것이 필요하지 않은 경우 코드는 훨씬 간단 할 수 있습니다.
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
다음 그림을 그립니다. 루프가 필요하지 않습니다.
코드의 특정 부분에 대한 질문이있는 경우 새로운 질문을하는 것이 좋습니다.
감사합니다. 당신이 모든 것을 설명하는 방법을 이해합니다! – Powisss