access data, handling data, delete and create index for new dataset

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

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

Sign in to comment.

Answers (1)

Sorry in attachment you can find the dataset.
I delete the columns
% delete the columns [3,5,6,10,16,18,19])
SensorData(:,[3,5,6,10,16,18,19])=[];
My table will be: 20631x16 that I will call SensorDataNew
% smooth the data
SmoothData = smooth(SensorDataNew)
% standardize the data
% pull out just the sensor data, ignoring unit and timestamp
xtrain = SmoothData{:,3:end};
% give all sensors mean of zero and the standard deviation of one
xtrainMean = mean(xtrain);
xtrainStd = std(xtrain);
xtrainStandard = (xtrain- repmat(xtrainMean, length(xtrain),1)./ repmat(xtrainStd,length(xtrain),1));
% reduction of dimensionality - Principal Component Analysis
[coeff,score,latent] = pca(xtrainStandard);
% visualize first and last points for each unit
% find the first and last point for each engine
[~,idx]= unique(SensorData.Unit);
idxLast = idx-1;
idxLast(idxLast<1)=[];
% compute centroid
idxCent = [mean(score(idxEng,1)), mean(score(idxEng,2))];
idxLastCent = [mean(score(idxEngLast,1)), mean(score(idxEngLast,2))];
% plot
figure(7)
plot(score(idx,1),score(idx,2),'.','MarkerSize',16); hold on;
plot(score(idxLast,1),score(idxLast,2),'r.','MarkerSize',16);
scatter(idxCent(1),idxCent(2),50,'g','^','filled')
scatter(idxLastCent(1),idxLastCent(2),50,'g','o','filled');
legend('1st point','last point','1st points cetroids',...
'last points centroid','Location', 'NorthWest');
title('First and Last point for Each Engine');
%% highlight problematic unit
idx = ismember(SensorData.Unit,[39,57,79,91]);
idx = idx & SensorData.Time > 1-(max(SensorData.Time)-20 ); %% last 20 cycle
figure (8); hold on;
plot(score(:,1),score(:,2),'.');
plot(score(idx,1),score(idx,2),'r.');
xlabel('first principal component');
ylabel('second principal component');
title('Last 20 cycle Flights of Problematic Unit Shown in Red');
but I want to make new table with only 125 cycle/time for each unit before smoothing, or if possible on table, smoothing only 125 cycle and delete the rest.

Categories

Products

Asked:

on 1 May 2021

Community Treasure Hunt

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

Start Hunting!