# Help with array and standard deviation

5 visualizaciones (últimos 30 días)
aurc89 el 13 de Oct. de 2014
I have a set of data saved in a file with two columns, x column and y column: for each value of x, a value of y is assigned. Let's suppose I have different files like this, saved separately, where the x values are always the same but the y column changes, i.e. the y value assigned to a certain x value is different for each file. What I want to do is: 1) load all these files , previously saved in a folder (I prefer to select the folder and let the program load them all together, since they are too many) and 2) for a given x, calculate the standard deviation of its corresponding y value (that changes from file to file). So, at the end I should have a file with two columns: one containing the x values (that are always the same) and one containing the standard deviations of the corresponding y values.
Thank you
##### 2 comentariosMostrar NingunoOcultar Ninguno
Adam el 13 de Oct. de 2014
What have you tried so far and which part of it are you having a problem with? Someone might come along and give you a heap of code for a generic solution, but most of us prefer to work with a little more specific information (with example data ideally) for giving help.
Your question title suggests you are having problem with the standard deviation.
However, your post suggests you are having issues with loading data in from files and saving to files as well as or instead of a problem with the standard deviation calculation.
aurc89 el 13 de Oct. de 2014
What I don't manage to do is to load more files simultaneously (giving to Matlab just the path of the folder containing them) and retrieve all the y values associated to each x

Iniciar sesión para comentar.

### Respuestas (2)

Star Strider el 13 de Oct. de 2014
This works:
x = [1:10]';
y = randi(25,10,5);
result = [x, std(y,[],2)];
Note that it is necessary to call std with an empty second argument, then specify that you want to take the std across rows (dimension 2), rather than the default of across columns (dimension 1).
##### 0 comentariosMostrar -2 comentarios más antiguosOcultar -2 comentarios más antiguos

Iniciar sesión para comentar.

Adam el 13 de Oct. de 2014
.mat files or text or binary files?
dirInfo = dir( folderName );
fileNames = { dirInfo( ~[dirInfo.isdir] ).name };
should give you a listing of all files in the current directory. If there are other files that you don't want to read in then you would have to filter these out. Otherwise just loop around the filenames and load them using the suitable file loading functions (depending whether they are .mat files or binary/text)
##### 0 comentariosMostrar -2 comentarios más antiguosOcultar -2 comentarios más antiguos

Iniciar sesión para comentar.

### Categorías

Más información sobre File Operations 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