access data, handling data, delete and create index for new dataset
Show older comments
Hi everyone,
I have dataset like this:
(20631x23)
Unit cycle Sensor1 Sensor2 Sensor(n) with n = 1:21
1 1 xxx xxx xxxx
1 2
1 3
1 .
1 .
1 125
1 .
1 192
2 1
2 .
2 .
2 287
3
3
3
3 328
n
.
.
.
1) For each unit 'n' I'd like to exctract only 125 cycle
2) delete sensor 1 column and sensor n column
2) After that I need the first and last point of each unit, in this way I'll have 2 idx vector.
In this way I have new dataset
I think about these 2 functions: unique and accumarray;
while, I tried this for idx:
[~,idxEng] = unique(Name_of_Table.Unit)
idxEngLast = idxEng-1
idxEngLast(idxEngLast<1)=[];
thanks
1 Comment
Scott MacKenzie
on 2 May 2021
I'm confused by your question. Seems you're using n both as a sensor number and as a unit number. Try to clarify, please.
Under the assumption that cycle 125 occurs only once in each unit, here's some code to get you started. It begins by creating a mock 50x5 dataset in table T with columns unit, cycle, sensor1, sensor2, and sensor3. It then retrieves all rows from T where the cycle is 125:
% create mock 50x5 dataset
unit = repmat(1:10,5,1);
unit = unit(:);
cycle = repmat([123 98 125 22 79]',10,1);
sensor1 = rand(50,1);
sensor2 = rand(50,1);
sensor3 = rand(50,1);
T = table(unit, cycle, sensor1, sensor2, sensor3);
% find and extract all rows for cycle #125
idxLogical = T.cycle == 125;
newT = T(idxLogical,:)
Output:
unit cycle sensor1 sensor2 sensor3
____ _____ ________ _______ ________
1 125 0.12367 0.60967 0.13197
2 125 0.050766 0.71249 0.24154
3 125 0.42856 0.53454 0.015727
4 125 0.59422 0.7402 0.1047
5 125 0.21723 0.9591 0.21357
6 125 0.03888 0.85537 0.53441
7 125 0.28128 0.29547 0.7967
8 125 0.99341 0.73486 0.99853
9 125 0.82731 0.33682 0.60422
10 125 0.30422 0.89803 0.91715
Answers (1)
salvatore cancemi
on 3 May 2021
Categories
Find more on Resizing and Reshaping Matrices in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!