Info

此问题已关闭。 请重新打开它进行编辑或回答。

Loops for a 3 D matrix

2 次查看(过去 30 天)
Lui
Lui 2018-10-30
关闭: MATLAB Answer Bot 2021-8-20
_Hi everyone I need to create a function that iterates through a table of two dimensions (n rows and about 60 columns - time series 5 minutes data for 60 different customers ). The iteration needs to be done for every time interval. To do this I need to construct a for loop that takes into consideration the iteration of time. How can this be implemented? How can all the variables generated be stored an retrieved without manually repeating the process. How does the for loop for this look like?
The following code works for one specific hour:_
% makes use of the DLR.mat file
% DLR.mat file represents the 1st half of the year 2000
load DLR.mat
%Hourly data from 2000/01/01 00:00 - end
sz = size(DLR); sz = sz(1);
i = 1;
n = numel(1:12:sz(1)); H = zeros(n, 61);
for N = 1:n
H(N, :) = table2array(DLR(i, 1:61));
i = i + 12;
end
hourly = array2table(H);
for N = 2:61
hourly.Properties.VariableNames{N} = convertStringsToChars(strcat('C', string(N-1)));
end
hourly.Date = (datetime(2000,01,01,0,0,0):hours(1):datetime('30-Jun-2000 23:55:00'))';
hourly = movevars(hourly, 'Date', 'Before', 'C0');
clearvars -except hourly DLR
% choose a reference time for the data to load
tref = datetime('01-Jan-2000 00:00:00');
hour = 0; % between 0 and 23
% select the date depending on the period you want
% Monthly, Weekly, Quaterly
dateFrom = datetime(2000,01,01,hour,0,0); %('01-Jan-2000 00:00:00')
dateTo = datetime('01-Jan-2000 23:55:00');
i = myDateToIndexFunction(dateFrom, tref);
j = myDateToIndexFunction(dateTo, tref);
data = DLR(i:j,:); %window between dateFrom and dateTo
% the intervals provide data for specifc hours. it shows the consumption for various consumers for the same hour
interval = 12; % 288 for day, 2016 for a week, Jan-Feb 8928,13104
sz = size(data); sz = sz(1);
a = 1;
clear hourly; %clear if it already exists
for N = 1:interval:sz
hourly(a, :) = data(N,:);
a = a + 1;
end
1.how do I loop the hours from 0 to 23
2.How do I store all the different hourly variables in one matrix for easy retrieval?

回答(0 个)

此问题已关闭。

标签

Community Treasure Hunt

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

Start Hunting!

Translated by