sort and collect data
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hi Guys, I have file that looks like this below (20 x 4) matrix. It consists of time, serial number, pessure and volume. I want to select the maximum value of pressure and the corresponding volume and time for each serial numbers every 4 secs all through the data. There are 4 items, serial number 1 represents the first, 2 the second, e.t.c. However the serial number 1 represents time where there is low/ no pressure as well. Could you help with this? Thanks
Time S/N Pressure Volume
00:00:01 1 20 2.4
00:00:02 1 25 2.5
00:00:03 1 30 2.6
00:00:04 1 35 2.7
00:00:05 1 0.3 2.8
00:00:06 1 1.4 2.9
00:00:07 2 20 3
00:00:08 2 30 3.1
00:00:09 2 40 3.2
00:00:10 2 50 3.3
00:00:11 1 0.6 3.4
00:00:12 1 1.5 3.5
00:00:13 3 20 3.6
00:00:14 3 30 3.7
00:00:15 3 40 3.8
00:00:16 3 50 3.9
00:00:17 1 0.1 4
00:00:18 1 2.3 4.1
00:00:19 4 20 4.2
00:00:20 4 30 4.3
00:00:21 4 34 4.4
00:00:22 4 50 4.5
00:00:23 1 0.3 4.6
00:00:24 1 4.1 4.7
2 commentaires
Adam Danz
le 6 Août 2019
Are there always 6 samples of each S/N and is S/N always in ascending order (except for the low pressure indicators)?
Réponse acceptée
Adam Danz
le 6 Août 2019
Modifié(e) : Adam Danz
le 7 Août 2019
Assuming you have 3 vectors named sn, pressure, and volume,
% Replace every 5th and 6th sn with 0
% * assumes that there will always be 4 samples of each SN
% followed by 2 low-pressure
sn(repmat(logical([0;0;0;0;1;1]),numel(sn)/6,1)) = 0;
% Identify groups of sn
[snGroupIdx, snGroup] = findgroups(sn);
% Calculate the max pressure within each group
maxPresSn = splitapply(@max,pressure,snGroupIdx);
% Find the volume that corresponds to the max pressure in each group
volumnSn = splitapply(@(x1,x2)x2(find(x1==max(x1),1)),pressure,volume,snGroupIdx);
% Put the results in a summary table
t = table(snGroup, maxPresSn, volumnSn, 'VariableNames', {'SN','MaxPres','Vol'});
Result
t = % FAKE DATA
5×3 table
SN MaxPres Vol
__ _______ ___
0 32 1
1 19 1
2 37 3
3 30 3
4 13 1
2 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Other Formats dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!