Help with operation of multiple files

4 views (last 30 days)
aurc89
aurc89 on 13 Oct 2014
Edited: per isakson on 14 Oct 2014
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 Comments
Stephen23
Stephen23 on 14 Oct 2014
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.

Sign in to comment.

Answers (1)

per isakson
per isakson on 13 Oct 2014
Edited: per isakson on 14 Oct 2014
&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 Comments
per isakson
per isakson on 14 Oct 2014
Use the documentation. It's actually rather good. See addendum to my answer.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!

Translated by