time series data set

조회 수: 4 (최근 30일)
Kushal Bhalla
Kushal Bhalla 2021년 5월 16일
댓글: Mathieu NOE 2021년 5월 25일
I have a dataset (279 * 96), for 9 different variables, with observations recorded at a fifteen minute interval for the month of January. I want a time series data of 9 variables (2976 * 9). Kindly help.

답변 (2개)

Mathieu NOE
Mathieu NOE 2021년 5월 16일
hello
try this - there is still a bit of work depending how you want the time axis of the plot being dispalyed
for the time being it's displayed by samples (one per 15 minutes )
hope it helps
T = readlines('data.csv');
% time vector is line 1
time = split(T{1},',');
% remove empty cells
empty = cellfun('isempty',time);
time(empty) = [];
time(1) = []; % remove also first cell with text "Date-Fuel"
%
%% main loop
data_Biomass = [];
data_Coal = [];
data_Gas = [];
data_Gas_CC = [];
data_Hydro = [];
data_Nuclear = [];
data_Other = [];
data_Sun = [];
data_Wind = [];
for ci = 2:numel(T)
if ~isempty(T{ci})
line = split(T{ci},',');
tmp = split(line{1},'-');
date{ci-1} = tmp{1};
variable = tmp{2};
if strcmp(variable,'Biomass')
data_Biomass = [data_Biomass; sbfct1(line)];
elseif strcmp(variable,'Coal')
data_Coal = [data_Coal; sbfct1(line)];
elseif strcmp(variable,'Gas')
data_Gas = [data_Gas; sbfct1(line)];
elseif strcmp(variable,'Gas_CC')
data_Gas_CC = [data_Gas_CC; sbfct1(line)];
elseif strcmp(variable,'Hydro')
data_Hydro = [data_Hydro; sbfct1(line)];
elseif strcmp(variable,'Nuclear')
data_Nuclear = [data_Nuclear; sbfct1(line)];
%
elseif strcmp(variable,'Other')
data_Other = [data_Other; sbfct1(line)];
elseif strcmp(variable,'Sun')
data_Sun = [data_Sun; sbfct1(line)];
elseif strcmp(variable,'Wind')
data_Wind = [data_Wind; sbfct1(line)];
end
end
end
% plots
figure(1);plot(data_Biomass)
figure(2);plot(data_Coal)
figure(3);plot(data_Gas)
figure(4);plot(data_Gas_CC)
figure(5);plot(data_Hydro)
figure(6);plot(data_Nuclear)
figure(7);plot(data_Other)
figure(8);plot(data_Sun)
figure(9);plot(data_Wind)
%%%%%%%%% sub function %%%%%%%%%%%
function out_data = sbfct1(line)
out_data = [];
temp = line(2:end);
empty = cellfun('isempty',temp);
temp(empty) = [];
out_data = cellfun(@str2double,temp);
end

Kushal Bhalla
Kushal Bhalla 2021년 5월 23일
Hello Sir,
Thanks a lot for your help. Appreciate! However, I am having problem executing the code.
While running the code which runs till the plots (not covering the code for the plots), I get the following error message:
Unrecognized function or variable 'sbfct1'.
Further, when I try to run the subfunction which contains sbfct1, I get the following error message:
function out_data = sbfct1(line)
Error: Function definition are not supported in this context. Functions can only be created as local or nested functions in code files.
  댓글 수: 1
Mathieu NOE
Mathieu NOE 2021년 5월 25일
hello
I tested again my code (R2020b) without a problem
if you have a recent matlab release , the subfunction can be nested in the main file (as I did) but the subfunctions must always be placed at the very end of the main code;
If you have an older matlab release, can you try saving the subfunction in a separate m. file - it must have the save name , sbfct1.m

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Tables에 대해 자세히 알아보기

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by