how to loop for a multiple variables array code?

Hello everybody. Just looking for some help about how to do a ´loop´ for the following code. The idea is to do the same the code does for every 30 minutes identified in the ‘C’ array (sometimes the 'C' array is not always 24h). Dataset attached. Thank you.
D = d;
t = time;
t = datevec(t);
[Ut,ia,idx] = unique(t(:,4)); % Unique Hours
Counts = accumarray(idx, 1); % Items In Each Hour
C = mat2cell(D, size(D,1), Counts);
%%setting variables
pws1=smoothdata((C{1,1}(:,[1:30])),'movmedian',3,'omitnan'); % 30 minutes for the period of time (00:00 - 00:30)
%%indentifiying peaks
ax1=subplot(2,2,1); % (2,2,1) for the first 30 minutes, (2,2,2) for the second group of 30 minutes, and so on...
load parts;
[pks,locs,widths1,proms2] = findpeaks(pws1(:,end),y,'MinPeakHeight',35); widths1;
findpeaks(pws1(:,end),y,'Annotate','extents','WidthReference','halfprom');
text(locs+0.5,pks,num2str((1:numel(pks))'));
legend('Filtered Data','Peak','Prominence','Width');
ax1.YAxisLocation = 'right';
ax1.XDir = 'reverse';
ax1.XGrid = 'on';
ax1.YGrid = 'off';
title ('Peaks (00:00 - 00:30)');
ylabel('Peaks identification','FontSize',9,'FontName','Arial','color','default');
xlabel('Altitude/km','FontSize',9,'color','default');
yticklabels('');
xlim(ax17,[75 95]);
ylim(ax17,[16 50]);
camroll(-90);
%%number of peaks found
numberpks1 =(findpeaks(pws1(:,end),y,'MinPeakHeight',20));

5 件のコメント

Jan
Jan 2021 年 4 月 23 日
I do not understand, what you are asking for.
Fercho_Sala
Fercho_Sala 2021 年 4 月 24 日
@Jan Yes, this code is designed for a period of 30 minutes, I just need to know how I can loop/repeat the same code for every period of 30 minutes within the ‘C’ array,,, for example this is one hour : C{1,1}, and this is the first 30 minutes of that hour : (C{1,1}(:,[1:30]) , as you can see 'C' has 24 arrays. It will be a waste of time (48 different codes) trying to type the same structures for the following 30 minutes an so on... Thanks.
Jan
Jan 2021 年 4 月 24 日
Then converting the array to a cell makes the problem harder. What about converting the time to minutes instead of a datevec and adding a loop like:
for minutes = 0:30:1440
index = minutes <= t & t < (minutes + 30);
data = D(index, :);
...
end
Fercho_Sala
Fercho_Sala 2021 年 4 月 26 日
@Jan ok I got it, but the issue is that '0:30:1440' will always work for 24h. For that reason I said "C is not always 24h" the number of arrays in 'C' changes and also the number of columns in each array of 'C' ;) , but your answer is interesting.
Jan
Jan 2021 年 4 月 26 日
0:30:1440 produces 30 minute intervals over 24 hours. Afterwards my code checks, how many elements are matching in the current time slot, so the data do not need to have 24 hours.

サインインしてコメントする。

 採用された回答

Steven Lord
Steven Lord 2021 年 4 月 24 日

0 投票

Consider converting your data array (with the time information) into a timetable and calling retime on it to aggregate each 30 minutes worth of data to compute the max in each period?
Or if your windows need to overlap use the movmax function.

1 件のコメント

Fercho_Sala
Fercho_Sala 2021 年 4 月 26 日
Sir, @Star Strider any coment about this code? Thanks.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeLoops and Conditional Statements についてさらに検索

製品

リリース

R2020b

質問済み:

2021 年 4 月 22 日

コメント済み:

Jan
2021 年 4 月 26 日

Community Treasure Hunt

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

Start Hunting!

Translated by