Effacer les filtres
Effacer les filtres

find a maximum for defined months and between a given times

30 vues (au cours des 30 derniers jours)
Hicham Belh
Hicham Belh le 24 Juin 2024 à 16:32
Commenté : Matlab Pro le 26 Juin 2024 à 7:12
Hi guys,
i try to find a maximum value in a given year timeserie. the seeked maximum for the months (jan, feb and december) have a given time range and for the months (Sept, oct and November) a different range. (see duration time in the code)
i tried my code but its not working. i guess i have a mistake in integrating the duration indexing and the logical check for the months.
any held how to correct the code will be nice.
thank you
filename='out.xlsx';
out=importdata(filename);
out=readtable('out');
M=month(out.Zeit(2:end));
ax=(M==1 | M==2 | M==12); % if month is januar, feb or december than ax=1
bx=(M==9 | M==10 | M==11);% if month is sept, oct or november than bx=1
tod=timeofday(out.Zeit(2:end));
p1w=(duration('07:45:00'):minutes(15):duration('16:15:00'))'; % fist time range we look for a max for ax
p2w=(duration('16:45:00'):minutes(15):duration('18:30:00'))'; % second time range we look for a max for ax
p3h=(duration('07:45:00'):minutes(15):duration('18:00:00'))'; % fist time range we look for a max for bx
ip1w=find((tod >= p1w(1) & tod <= p1w(end)) | (tod >= p2w(1) & tod <= p2w(end))); % look for the index of p1w and p2w
ip2h=find((tod >= p3h(1) & tod <= p3h(end))); % look for the index of p3h
maxW=max(out.SV(ax(ip1w)==1)); % max if conditions of time range and month are filled for ax
maxH=max(out.SV(bx(ip2h)==1)); % max if conditions of time range and month are filled for bx
maxHLZ=max(maxW,maxH);

Réponse acceptée

Matlab Pro
Matlab Pro le 25 Juin 2024 à 8:32
I think you have some problems in your code;
  1. while chopping Zeit (out.Zeit(2:end)) --> you did not chop SV (out.SV)
  2. There is a mis-correlation with the indexes created by: ax(ip1w)==1 or bx(ip2h)==1 with relation to out.SV
I have done some fixes to the code. See if it is OK now..
filename='out.xlsx';
out=importdata(filename);
out=readtable('out');
M=month(out.Zeit(2:end));
ax=(M==1 | M==2 | M==12); % if month is januar, feb or december than ax=1
bx=(M==9 | M==10 | M==11);% if month is sept, oct or november than bx=1
tod=timeofday(out.Zeit(2:end));
p1w=(duration('07:45:00'):minutes(15):duration('16:15:00'))'; % fist time range we look for a max for ax
p2w=(duration('16:45:00'):minutes(15):duration('18:30:00'))'; % second time range we look for a max for ax
p3h=(duration('07:45:00'):minutes(15):duration('18:00:00'))'; % fist time range we look for a max for bx
% ip1w=find((tod >= p1w(1) & tod <= p1w(end)) | (tod >= p2w(1) & tod <= p2w(end))); % look for the index of p1w and p2w
% ip2h=find((tod >= p3h(1) & tod <= p3h(end))); % look for the index of p3h
ip1w=(tod >= p1w(1) & tod <= p1w(end)) | (tod >= p2w(1) & tod <= p2w(end)); % look for the index of p1w and p2w
ip2h=(tod >= p3h(1) & tod <= p3h(end)); % look for the index of p3h
SV = out.SV(2:end); % Chop 1st entry (as done in: out.Zeit(2:end))
b = false(size(ax));
f = find(ip1w); % get specific indexes
idx = ax(f) == 1; % get the indexes of change
b(f(idx)) = 1; % .. and change values
maxW=max(SV(b)); % max if conditions of time range and month are filled for ax
b = false(size(ax));
f = find(ip2h); % get specific indexes
idx = ax(f) == 1; % get the indexes of change
b(f(idx)) = 1; % .. and change values
maxH=max(SV(b)); % max if conditions of time range and month are filled for ax
% maxW=max(SV(ax(ip1w)==1)); % max if conditions of time range and month are filled for ax
% maxH=max(SV(bx(ip2h)==1)); % max if conditions of time range and month are filled for bx
maxHLZ=max(maxW,maxH);
  2 commentaires
Hicham Belh
Hicham Belh le 25 Juin 2024 à 13:20
Hi Matlab Pro,
thank you for the response.
u got it. the correlation was not correct and the use of out.Zeit also.
thank you very much for the great support.
Matlab Pro
Matlab Pro le 26 Juin 2024 à 7:12
@Hicham Belh - happy to assist

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Calendar dans Help Center et File Exchange

Produits


Version

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by