MATLAB Answers

time series data set

1 view (last 30 days)
Kushal Bhalla
Kushal Bhalla on 16 May 2021
Commented: Mathieu NOE on 25 May 2021
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.

Answers (2)

Mathieu NOE
Mathieu NOE on 16 May 2021
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)];
% plots
%%%%%%%%% sub function %%%%%%%%%%%
function out_data = sbfct1(line)
out_data = [];
temp = line(2:end);
empty = cellfun('isempty',temp);
temp(empty) = [];
out_data = cellfun(@str2double,temp);

Kushal Bhalla
Kushal Bhalla on 23 May 2021
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 Comment
Mathieu NOE
Mathieu NOE on 25 May 2021
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

Sign in to comment.


Community Treasure Hunt

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

Start Hunting!