Help with array and standard deviation

1 次查看(过去 30 天)
aurc89
aurc89 2014-10-13
编辑: Adam 2014-10-13
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 个评论
Adam
Adam 2014-10-13
编辑:Adam 2014-10-13
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
aurc89 2014-10-13
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

请先登录,再进行评论。

回答(2 个)

Star Strider
Star Strider 2014-10-13
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).

Adam
Adam 2014-10-13
编辑:Adam 2014-10-13
.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)

类别

Help CenterFile Exchange 中查找有关 File Operations 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by