Getting average for a range of data on a plot. Not entire range, only for a section.
8 ビュー (過去 30 日間)
古いコメントを表示
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 件のコメント
Dyuman Joshi
2023 年 10 月 14 日
"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.
採用された回答
dpb
2023 年 10 月 14 日
移動済み: dpb
2023 年 10 月 14 日
"... 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
data(1:5,:)
plot(data(:,2))
findchangepts(data(:,2),'Statistic','mean')
yf=medfilt1(data(:,2),5);
findchangepts(yf)
[yf(1) yf(1500) yf(1)-yf(1500)], (yf(1)-yf(1500))/yf(1)*100
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))
[min(yf) max(yf) range(yf)]
[min(yf(1:900)) max(yf(1:900)) range(yf(1:900))]
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.
その他の回答 (1 件)
参考
カテゴリ
Help Center および File Exchange で Multirate Signal Processing についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!