Extract plot statistics for a specific range

14 次查看(过去 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.
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

回答(2 个)

Star Strider
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)
xds = struct with fields:
num: 250 max: 20 min: 0 mean: 10 median: 10 range: 20 std: 5.8083
yds = struct with fields:
num: 250 max: 1.2744 min: -1.2245 mean: 0.0014 median: 0.0201 range: 2.4989 std: 0.5211
Lv = x >= 2 & x <= 4; % Logical Vector
[xds24,yds24] = datastats(x(Lv),y(Lv))
xds24 = struct with fields:
num: 25 max: 3.9357 min: 2.0080 mean: 2.9719 median: 2.9719 range: 1.9277 std: 0.5911
yds24 = struct with fields:
num: 25 max: 0.4296 min: -1.2245 mean: -0.5585 median: -0.6942 range: 1.6541 std: 0.4971
Make appropriate variable name changes to work with your data.
.

phenan08
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).

类别

Help CenterFile Exchange 中查找有关 Measurements and Feature Extraction 的更多信息

产品


版本

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by