Separating data into one-second intervals, and finding the maximum data in each interval

조회 수: 7 (최근 30일)
I have a 2 column matrix with around1300 data per second and measurements in total between 40-80 seconds, the exact number of data is not certain. I'm trying to print the largest three data and the smallest three values in every second in the matrix I have. I think my algorithm knowledge is insufficient for this. Is there anyone who can help?
load("Green6000X.csv")
b12xtime=Green6000X(:,1);
b12xacc=Green6000X(:,2);
u=0:5:height(b12xtime);
v=zeros(138,1);
for i=1:height(b12xtime)
a=find(b12xtime(:,1)<=i);
b=find(b12xtime(:,1)<=i+1);
t(i,1)=height(a);
s(i,1)=height(b);
% val=abs(s-t);
for x=t(i):s(i)
c(x,1)=b12xacc(x,1);
d=max(c);
b=height(s);
n=height(t);
v(x,1)=d;
if(v(x-1,1)==v(x,1))
v(x-1,1)=0;
end
end
clear c;
end
column= find(v==0);
for i=1:length(column)
column= find(v==0);
v(column(1),:) = [];
end
  댓글 수: 1
Emre Can Yilmaz
Emre Can Yilmaz 2022년 4월 21일
편집: Image Analyst 2022년 4월 21일
This time I tried a different code for maximum value. It takes a very long time to run, about 30 minutes. I don't even know if your conclusion is correct.
load("Green6000X.csv")
b12xtime=Green6000X(:,1);
b12xacc=Green6000X(:,2);
lastValueOfTime=ceil(b12xtime(end));
for ii=0:lastValueOfTime
for i=1:height(b12xtime)
a=find(b12xtime(:,1)<=i);
b=find(b12xtime(:,1)<=i+1);
t(i,1)=height(a);
s(i,1)=height(b);
% val=abs(s-t);
for x=t(i):s(i)
c(x,1)=b12xacc(x,1);
d=max(c);
v(x,1)=d;
if(v(x-1,1)==v(x,1))
v(x-1,1)=0;
end
end
end
end
for i=1:length(column)
column= find(v==0);
v(column(1),:) = [];
end

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

채택된 답변

per isakson
per isakson 2022년 4월 21일
%% load data
num = load('Green6000X.csv');
%% split data into chunks of one second
N = ceil( num(end,1) );
chunk = cell( 1, N );
ixb = 1;
for jj = 0 : N-2
ixe = find( num(:,1) >= jj+1, 1, 'first' );
chunk{jj+1} = num( ixb:ixe-1, : );
ixb = ixe;
end
chunk{N} = num(ixb:end,:);
%% calculate max for each chunk
v = nan( N, 1 );
for ii = 1 : N
v(ii) = max( chunk{ii}(:,2) );
end
%% first three and the last three values of each chunk
three = nan( N, 6 );
for ii = 1 : N
three(ii,:) = reshape( chunk{ii}([1:3,end-2:end],2), 1,[] );
end
  댓글 수: 2
Emre Can Yilmaz
Emre Can Yilmaz 2022년 4월 21일
This was exactly the solution I wanted, thank you very much.
per isakson
per isakson 2022년 4월 21일
편집: per isakson 2022년 4월 21일
Response to "Can we also write the largest three data and the smallest three in the part?"
Add the section below to the script
%% the largest three data and the smallest three of each chunk
min3max3 = nan( N, 6 );
for ii = 1 : N
min3max3(ii,:) = [ reshape( mink( chunk{ii}(:,2), 3 ), 1,[] ) ...
reshape( maxk( chunk{ii}(:,2), 3 ), 1,[] ) ];
end
I don't understand "in the part"

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

추가 답변 (1개)

KSSV
KSSV 2022년 4월 21일
As you said data is from 40-80 seconds and each second has 1300 data points, you can pick the first 40*1300 rows and reshape the data.
T = readtable('Green6000X.csv') ;
d = reshape(T.(2)(1:40*1300),1300,40) ;
% first three elements of each second
d(:,1:3)
% last three elements of each second
d(:,end-3:end)
% max in each row
max(d,[],2)
  댓글 수: 3
KSSV
KSSV 2022년 4월 21일
You can get the time step to equal, append NaN's at the end and then use reshape.

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

카테고리

Help CenterFile Exchange에서 Large Files and Big Data에 대해 자세히 알아보기

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by