0
votes

How can I find the the starting point of A array and calculate average starting from starting points to 1 second

A=[0 0 0 0 0 -0.01 -0.2 0.3 0.4 0.5 0 0 0 0 0 0 0.01 0.02 0.03 0.04 0.1 0.2 0.3 0.4 0.7 0.8 1 1.2 1.3 1.4 1.5]

Time=[0 0.1 .2 .3 .4 .5 .6 .7 .8 .9 1 1.2 1.3 1.4 1.5 1.6 1.7 1.8 1.9 2 2.1 2.2 2.3 2.4 2.5 2.6 2.7 2.8 2.8 3 3.1]

By removing the noise the starting point should be A(17) which is equal to 0.01

Then calculate average of A starting from starting point after 1 seconds

2
What is B array ?Paolo
its A array i edited my question. Thanksuser183060
What kind of values are considered as noise here?Rijul Sudhir
noise values are from A(6) to A(10). I want data starting from the first nonzero where the graph becomes constant and will not become zero againuser183060
So largest set of non zero values occurring continuously is considered as data right?Rijul Sudhir

2 Answers

1
votes

Code is self explanatory

A=[0 0 0 0 0 -0.01 -0.2 0.3 0.4 0.5 0 0 0 0 0 0 0.01 0.02 0.03 0.04 0.1 0.2 0.3 0.4 0.7 0.8 1 1.2 1.3 1.4 1.5] ;
Time=[0 0.1 .2 .3 .4 .5 .6 .7 .8 .9 1 1.2 1.3 1.4 1.5 1.6 1.7 1.8 1.9 2 2.1 2.2 2.3 2.4 2.5 2.6 2.7 2.8 2.8 3 3.1];

%make negative values zero
A(A<0)=0; 

%get non negative values position and add padding
mask=[0,A>0,0]; 

%get starting points
startingPoints =strfind(mask,[0 1]); 

%get length of continuous values from starting points
temp =diff(find(~mask))-1;
length = temp(temp>0); 

%get the index of largest length
[~,index]=max(length);

%get starting point
dataStartingIndex = startingPoints(index)

%starting point value
A(dataStartingIndex)

%get ending point after 1 seconds
dataEndingIndex=find((Time(dataStartingIndex)+1)==Time);

%find average
avg=mean(A(dataStartingIndex:dataEndingIndex))
0
votes

This really depends on your data. It is a bit unclear but in your example it seems that noise can exceed your 'information value'. So you can't detect it just with a threshold. Maybe get the position where A is always superior to something like 0.01 :

startpos= (A>0).argmax()
truedata=A[startpos:]
time=T[startpos:]

you can calculate average with the method .mean()