# Help with array and standard deviation

2 views (last 30 days)
aurc89 on 13 Oct 2014
Edited: Adam on 13 Oct 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 CommentsShowHide 1 older comment
aurc89 on 13 Oct 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

Sign in to comment.

### Answers (2)

Star Strider on 13 Oct 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 CommentsShowHide -1 older comments

Sign in to comment.

Adam on 13 Oct 2014
Edited: Adam on 13 Oct 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 CommentsShowHide -1 older comments

Sign in to comment.

### Categories

Find more on Whos in Help Center and File Exchange

### Community Treasure Hunt

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

Start Hunting!

Translated by