Help with operation of multiple files

조회 수: 3 (최근 30일)
aurc89
aurc89 2014년 10월 13일
편집: per isakson 2014년 10월 14일
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
aurc89
aurc89 2014년 10월 14일
편집: aurc89 2014년 10월 14일
Actually I'm interested only in x_m values, but a < nx2 double array> is ok anyway
Stephen23
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
per isakson 2014년 10월 13일
편집: per isakson 2014년 10월 14일
&nbsp
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!
&nbsp
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
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
per isakson 2014년 10월 14일
Use the documentation. It's actually rather good. See addendum to my answer.

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

카테고리

Help CenterFile Exchange에서 Structures에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by