# Help with array and standard deviation

조회 수: 6 (최근 30일)
aurc89 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없음 표시없음 숨기기
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 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 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).
##### 댓글 수: 0이전 댓글 -2개 표시이전 댓글 -2개 숨기기

댓글을 달려면 로그인하십시오.

.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