Help with array and standard deviation
1 view (last 30 days)
Show older comments
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 Comments
Adam
on 13 Oct 2014
Edited: Adam
on 13 Oct 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.
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 Comments
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 Comments
See Also
Categories
Find more on File Operations 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!