Help with operation of multiple files
조회 수: 4 (최근 30일)
이전 댓글 표시
I have a set of data saved in a file (Test.time.00001.Master.Scope) 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 (Test.time.00002.Master.Scope, Test.time.00003.Master.Scope...), saved separately in a folder. Can you suggest me a code doing the following instructions?
1) load these files all together, simply giving to the program the path of the folder containing them (I don't know how to do this)
2) calculate the maximum value of y column, ymax, and the associated value of x , x_m, for every file
3) save all these x_m values in a vector called z
Thank you
댓글 수: 3
Stephen23
2014년 10월 14일
Please edit your question and tell us what file format these files use. Without knowing this critical piece of information, it is impossible to say how you should load the data into MATLAB.
답변 (1개)
per isakson
2014년 10월 13일
편집: per isakson
2014년 10월 14일
 
Assumptions: The files you want to read are the only files matching *.txt in the folder
I would use a script looking something like this
folder_with_data = 'c:\your\folder\with\data';
sad = dir( fullfile( folder_with_data, '*.txt' ) );
z = nan( length( sad ), 2 );
for jj = 1 : length( sad )
filespec = fullfile( folder_with_data, sad(jj).name );
x_y = dlmread( filespec, 'Delimiter', '' );
[ ~, ix_max ] = max( x_y(:,2) );
z( jj, : ) = x_y( ix_max, : );
end
I leave testing to you!
 
Addendum
Replace
sad = dir( fullfile( folder_with_data, '*.txt' ) );
by
sad = dir( fullfile( folder_with_data, 'Test.time.*.Master.Scope' ) );
and replace
'Delimiter', ''
by
'Delimiter', ';'
where ';' stands for your list separator character. (or remove 'Delimiter','', default might do it.)
댓글 수: 3
Stephen23
2014년 10월 14일
편집: Stephen23
2014년 10월 14일
There is a great variety of file formats in the world, and MATLAB does not intuitively know about them all. This would be impossible.
To read data from some data file, you can try one of the inbuilt functions (eg csvread , dlmread, readtable , etc.
You should browse MATLAB's contents on different file reading (and writing) functions. Please browse and read these pages, they include many useful functions, complete with working examples.
If those standard file reading functions do not cover the format of your data, you can try to find something on MATLAB File Exchange , or use a low-level file reading function, such as fscanf or fread (in which case you will need to know about the formatting and encoding of the data in the file).
per isakson
2014년 10월 14일
Use the documentation. It's actually rather good. See addendum to my answer.
참고 항목
카테고리
Help Center 및 File Exchange에서 Structures에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!