Importing data into PIVMat

Importing data into PIVMat



The function loadvec allows to import data from several file formats into PIVMat structures for further processing. See the page Data organisation in PIVMat to learn more about PIVMat structures.

Supported file formats

PIVMat supports files from:

Text-based formats

Most of the common PIV softwares export files in plain text format, with suffix .TXT, .DAT or .VEC. Text files must have the following format

Headerlines (optional)
x1 y1 u v
x2 y1 u v
x3 y1 u v
...
x1 y2 u v
x2 y2 u v
...
where x,y are the coordinates and u,v the vector components. The data may be separated by spaces or commas. If there are more than 4 columns, the additional columns are ignored. The data must be organized on a rectangular grid.

DaVis format

If you work with DaVis, it is possible (and recommended) to import the files directly in DaVis format (suffix .VC7), not in text mode. For this, you must first install the Lavision's ReadIMX package: See the Installation page.

Importing a single file

If you are in a directory containing PIVMat-compatible files (e.g. .VEC, .TXT, .VC7, .MAT files), you can load a single field into a PIVMAT structure using the function loadvec:

v = loadvec('B00001.vc7');
But loadvec offers a lot of possibilities to import series of files, using wildcards (*), file numbering etc.

Examples in this page are provided for .VC7 files (from DaVis), but they work similarly for the other supported files.

Importing files using the wildcard (*)

In order to import all the files of the current directory into a structure array, simply use

v = loadvec('*')

It is also possible to import files belonging to different directories, using wildcards (*) in the path names like this:

v1 = loadvec('*Loop=1*/PIV*/*.vc7');
v2 = loadvec('*Loop=2*/PIV*/*.vc7');
You can also concatenate all the files into a big PIVMat structure like this:
v = loadvec('*Loop*/PIV*/*.vc7');
You can also load the first file of each directory Loop=* like this:
v = loadvec('*Loop*/PIV*/B00001.vc7');

See also loadarrayvec to import different files from different directories under two-dimensional structure arrays.

Importing files using file enumeration (without brackets [])

Suppose the files are named B00001.vc7, B00002.vc7 etc. (standard DaVis file naming convention). If you want to load files 1 to 10, you can use the following syntax:

v = loadvec(1:10);
You can use all Matlab ways to enumerate numbers, e.g.
v = loadvec([1 10 12:20]);
or
v = loadvec(100:-1:1);

Importing files using file enumeration (with brackets [])

Another convenient way to import some specified files is the file enumeration operator, coded with brackets [...] in the filename.

For instance, to load the first 5 files from the Loops number 1 to 3 only, use

v = loadvec('*Loop=[1:3,1]*/PIV*/B[1:5].vc7');

The bracket syntax is [RANGE, NZ], where RANGE is a range of numbers in the Matlab syntax (e.g. 1:10, 1:2:10, 10:-1:1 etc), and NZ specifies the number of zeros to pad the result (5 by default). For instance, [1:4,3] is equivalent to 001, 002, 003, 004.

You can also use non-integer indices, using the syntax [RANGE, NZ.NP], where NZ is the total number of characters of the index, and NP is the number of digits after the decimal point (if not specified, NP=0).

For instance, suppose your files (originating from a 4-Hz acquisition system) have names in the form:

You can import the files from time 10 to 14 s by steps of 0.5 s using
v = loadvec('My*_t[10:0.5:14,7.2]*.mat');

Importing files using for loops

If you can't store all your files into a single PIVMat structure (lack of memory), then you will have to make a direct loop over your files. This can be readily done using the function rdir:
file = rdir('*.vc7');
for i=1:length(file)
   v = loadvec(file{i});
   st = statf(vec2scal(v,'ken'));
   k(i) = st.mean;
end;
plot(k);
(note the use of curly braces {} for cell arrays of strings - see rdir for details).

Saving / reloading files

Once a set of DaVis files have been imported into a PIVMat structure v, you can perform a number of computations, e.g.
v = loadvec('*Loop*/PIV*/*.vc7');
nv = filterf(medianf(rotatef(v,pi/8));
You can save your modified fields nv into standard Matlab's MAT files using the command save:
save('myfields.mat','nv');
Those Matlab files may be loaded either using standard Matlab's load command or, more conveniently, directly using loadvec:
v = loadvec('myfields.mat');
Note that the file myfields.mat only needs to contain at least one PIVMat-compatible structure for this to work, whatever its name. Here, loadvec recognizes the PIVMat structure nv in the file, and outputs it under the new name v.

Using DaVis files without the ReadIMX package

DaVis uses various file formats (VC7, IM7 and others) which can be imported into Matlab using the ReadIMX package provided by LaVision.

It is also possible to translate the DaVis files into standard Matlab MAT files, that can be further processed on systems without ReadIMX. For this purpose, use the function vec2mat. Use for instance

vec2mat('*.vc7');
to translate all the VC7 files from the current directory into MAT files with the same name (e.g. B00001.MAT, B00002.MAT etc). Those MAT files can be re-loaded as usual using the loadvec function, e.g.
v = loadvec('*.mat');

Navigation through files

Data files are often organized in trees of folders and subfolders. PIVMat provides a number of command-line functions to easily navigate through these folders: rdir, cdw, lsw.

With the use of wildcards (*) and file enumeration with brackets ([]), loadvec allows you to easily import files from the right (sub)directories of the DaVis hierarchy.

Here is an example of files in a DaVis project

In order to easily navigate in this tree, using the number of the loop Loop=x for instance, you can use the functions cdw and lsw (analogous to cd and ls with wildcards *):

cdw *Loop=2*

Importing other types of DaVis files

The function loadvec is also able to import DaVis image files (IMX, IMG and IM7 files).

In order to import DaVis .SET and .EXP files, use readsetfile.



 

2005-2021 PIVMat Toolbox