Extract plot statistics for a specific range
13 次查看(过去 30 天)
显示 更早的评论
Hi all, hope you are well.
I have a very basic question regarding the Data Statistics tool.
I'm plotting several acoustic metrics (such as sharpness, fluctuation strength etc) and am able to import data files (.wav) and plot the data without any issues. I have also made use of the Data Statistics tool to calculate the mean and max of the plotted data.
What I'm trying to do now is extract the data statistics for a specific range of the data - for example, the mean sharpness between 2 and 4 seconds of the audio file.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1434988/image.jpeg)
I'm sure there is a way to do this with some code etc - but I was hoping there would be a way to do it interactivly within the plot - almost like a set of cursors which can be moved which set the start and end points?
Any help is gratefully recieved.
All the best,
Andy
0 个评论
回答(2 个)
Star Strider
2023-7-15
I don’t have the Curve Fitting Toolbox, however looking at the documentation for the datastats function, one option would be:
Lv = x >= 2 & x <= 4; % Logical Vector
[xds,yds] = datastats(x(Lv),y(Lv))
That should give you the result you want.
Example —
x = linspace(0, 20, 250).';
y = sin(2*pi*x/10) .* cos(2*pi*x/5) + randn(size(x))/5;
figure
plot(x, y)
grid
[xds,yds] = datastats(x, y)
Lv = x >= 2 & x <= 4; % Logical Vector
[xds24,yds24] = datastats(x(Lv),y(Lv))
Make appropriate variable name changes to work with your data.
.
0 个评论
phenan08
2023-7-15
编辑:phenan08
2023-7-15
You can try data selection using ginput. Example below:
x = rand(100,1) ; % generation of fake data
y = rand(100,1) ; % generation of fake data
figure ;
plot(x,y,"o") ;
selection = ginput(2) ; % selection of the bounds in the plot
tf = x >= min(selection(:,1)) & x <= max(selection(:,1)) ; % test to check whether the data belong to the selected interval or not
figure ;
plot(x(tf),y(tf),"o") ; % plotting the selected data
Then you can make data statistics on the selected data x(tf) and y(tf).
0 个评论
另请参阅
类别
在 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!