Getting average for a range of data on a plot. Not entire range, only for a section.

9 visualizaciones (últimos 30 días)
I have a plot in matlab from a csv file. I read the file using readmatrix. See below.
I need to get the average for each one of the steps in the graph below.
If anyone could help it would be appreciated.
  6 comentarios
Dyuman Joshi
Dyuman Joshi el 14 de Oct. de 2023
"I can find the points manually"
Once again, by what criteria?
Do you take a x-coordinate which is smaller than the previous one by a threshold to be the starting point? And the x-coordinate which is smaller than the next one by a threshold to be the ending point?
If so, then what is the threshold?
Also, please attach the data you are working with.
Pieter Joubert
Pieter Joubert el 14 de Oct. de 2023
The data is attached.
So for the threshold. There is not a specific criteria which I can use. If you look at the graph, it must just be for a range of values where the sensor reaches steady state because the sensor contains noise. Even if it is just for 100 values in the steady state area it will be fine. I just need the mean value of all the values at steady state.
Thanks for your help thus far.

Iniciar sesión para comentar.

Respuesta aceptada

dpb
dpb el 14 de Oct. de 2023
Movida: dpb el 14 de Oct. de 2023
"... the data is from a wind tunnel analysis and each step is when the frequency of the fan changes. ..."
So, you didn't record the fan setpoint speed, too? Use it to find the places it changes...
Or,
d=dir('*.csv');
data=readmatrix(d.name);
whos data
Name Size Bytes Class Attributes data 7487x2 119792 double
data(1:5,:)
ans = 5×2
NaN 100621 NaN 100616 NaN 100617 NaN 100618 NaN 100618
plot(data(:,2))
findchangepts(data(:,2),'Statistic','mean')
Generally, findchangepts does pretty well, but it didn't do so good here...wonder what
yf=medfilt1(data(:,2),5);
findchangepts(yf)
[yf(1) yf(1500) yf(1)-yf(1500)], (yf(1)-yf(1500))/yf(1)*100
ans = 1×3
100616 100580 36
ans = 0.0358
i1=find((yf(1)-yf)>35,1);
hold on
plot(i1,yf(i1),'rx')
The issue here is the change in levels is a very small fraction of the total signal level and while it is pretty large with respect to the noise in the signal and steady state, it is hard to distinguish the difference between overall means.
What else do you know of the experiment other than this one result that might be useful -- like do you know a priori how many fan levels were in the experimental run and that they were roughly same time lengths at each level, for example? That would give you some help in segregating the time trace and looking for changes.
findchangepts(yf(1:2250))
does pretty well if can look at the smaller segments. Might have to resort to some iterative technique such as the above making assumptions about the length of each subset.
@Image Analyst's idea of histogram might work out; that's a good observation on his part...except the binning may be needed to be quite fine; the following seems to mix the first/last together, maybe...
histogram(yf)
std(yf(1:900))
ans = 2.6217
[min(yf) max(yf) range(yf)]
ans = 1×3
100144 100631 487
[min(yf(1:900)) max(yf(1:900)) range(yf(1:900))]
ans = 1×3
100611 100627 16
histogram(yf,[min(yf):20:max(yf)])
That does return the six plateaus based on a guesstimate of what the in-plateau spread looks like; one could then
ibin=discretize(yf,[min(yf):20:max(yf)]);
that would tell you the bin of each element and then by finding the largest bin counts to locate the bins, one could then compute means based on those and check the boundaries graphically.

Más respuestas (1)

Image Analyst
Image Analyst el 14 de Oct. de 2023
"I just need the mean value of all the values at steady state." <== So use histogram or histcounts.

Etiquetas

Productos


Versión

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by