필터 지우기
필터 지우기

find a maximum for defined months and between a given times

조회 수: 30 (최근 30일)
Hicham Belh
Hicham Belh 2024년 6월 24일 16:32
댓글: Matlab Pro 2024년 6월 26일 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);

채택된 답변

Matlab Pro
Matlab Pro 2024년 6월 25일 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
Hicham Belh
Hicham Belh 2024년 6월 25일 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.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Calendar에 대해 자세히 알아보기

제품


릴리스

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by