Importing data into PIVMat

Importing data into PIVMat

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

PIVMat supports files from:

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

If you are in a directory containing PIVMat-compatible files (files with suffix .VC7, .MAT etc.), 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.

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]);
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;
(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:
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

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');

DaVis files organization

Files in DaVis 7 are organized by default into a specific tree of folders and subfolders. PIVMat provides a number of command-line functions to easily navigate through those 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 DaVis project content:

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-2016 PIVMat Toolbox