Calculating standard deviation of matrix
16 次查看(过去 30 天)
显示 更早的评论
ADS = audioDatastore(folder);
while hasdata(ADS)
x=read(ADS);
P=8; % no of neighbours for computation
b_right=zeros(1,4); % variables for computing differnces on sides
b_left=b_right;
[row,c]=size(x); % total number of samples is "row"
total_frames=row/9;% number of total frames as 1 Frames=9 samples
% so total frames = total samples/ frame size
% full_frame=zeros(9,500);
h=row/9;
g=std(h, 'all');
So I want to calculate standard deviation of each sample in a frame. There are 9 samples in each frame. and want to show the result in g. Currently g is returning 0 value. I want my code to compute the standard deviation of each sample in single frame.
0 个评论
采纳的回答
Dana
2020-8-31
I'm not sure I quite understand what you want, but a couple of things I see. First, row is a scalar giving the number of rows in z, and therefore h=row/9 is also just a scalar. In that case, g=std(h) is the standard deviation of a set made up of the single number h, which, by convention, equals 0.
I'm guessing you really want to compute standard deviations of sub-groups of the elements of x. Is x a vector or a matrix (i.e., is c=1 or >1)?
If x is a vector, and you want to compute standard deviations of each successive, non-overlapping group of 9 elements of x, then if the number of elements of x is an even multiple of 9 (i.e., if h=row/9 is an integer), you can do this easily via
x2 = reshape(x,9,h); % reshape the vector x into a matrix with 9 rows and h columns
g = std(x2,1); % compute the standard deviation of each column
If h is not an integer, it means your last frame will have less than 9 samples in it. You have to figure out how you want to deal with that. For example, you may want to compute standard deviations only for frames with 9 elements in them, in which case:
flh = floor(h); % round h downward
x2 = reshape(x(1:9*flh),9,flh); % reshape the first 9*flh elements of x into a 9-by-flh matrix
g = std(x2,1); % compute the standard deviation of each column
If x is a matrix, then you need to provide some more detail about exactly what you're computing the standard deviation of.
2 个评论
Dana
2020-9-1
As I said in my previous post, "If x is a matrix, then you need to provide some more detail about exactly what you're computing the standard deviation of." So if you want additional help, you'll have to clarify the problem you're trying to solve here.
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!