필터 지우기
필터 지우기

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개)

이 질문은 마감되었습니다.

태그

제품


릴리스

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by