- while chopping Zeit (out.Zeit(2:end)) --> you did not chop SV (out.SV)
- There is a mis-correlation with the indexes created by: ax(ip1w)==1 or bx(ip2h)==1 with relation to out.SV
find a maximum for defined months and between a given times
4 views (last 30 days)
Show older comments
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);
0 Comments
Accepted Answer
Matlab Pro
on 25 Jun 2024
Hi @Hicham Belh
I think you have some problems in your code;
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 Comments
More Answers (0)
See Also
Categories
Find more on Language Fundamentals in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!