Help with operation of multiple files

4 visualizaciones (últimos 30 días)
aurc89
aurc89 el 13 de Oct. de 2014
Editada: per isakson el 14 de Oct. de 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 comentarios
aurc89
aurc89 el 14 de Oct. de 2014
Editada: aurc89 el 14 de Oct. de 2014
Actually I'm interested only in x_m values, but a < nx2 double array> is ok anyway
Stephen23
Stephen23 el 14 de Oct. de 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.

Iniciar sesión para comentar.

Respuestas (1)

per isakson
per isakson el 13 de Oct. de 2014
Editada: per isakson el 14 de Oct. de 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 comentarios
Stephen23
Stephen23 el 14 de Oct. de 2014
Editada: Stephen23 el 14 de Oct. de 2014
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 el 14 de Oct. de 2014
Use the documentation. It's actually rather good. See addendum to my answer.

Iniciar sesión para comentar.

Categorías

Más información sobre Cell Arrays en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by