Calculating standard deviation of matrix

15 visualizaciones (últimos 30 días)
Ralph
Ralph el 31 de Ag. de 2020
Editada: Ralph el 9 de Sept. de 2020
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.

Respuesta aceptada

Dana
Dana el 31 de Ag. de 2020
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 comentarios
Ralph
Ralph el 1 de Sept. de 2020
Thank you soo much, your answer is really appreciated. Yes x is a matrix.
Dana
Dana el 1 de Sept. de 2020
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.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Data Distribution Plots en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by