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.
This page only describes import from DaVis (LaVision GmbH) files only. However, it works similarly for the other file formats supported by PIVMat (VidPIV, MatPIV...).
If you are in a directory containing DaVis files of vector fields (files with suffix .VEC or .VC7), you can load a single field into a PIVMAT structure using the function loadvec:
But loadvec offers a lot of possibilities to import series of files, using wildcards (*), file numbering etc. For instance, in order to import all the files of the current directory into a structure array, simply usev = loadvec('B00001.vc7');
v = loadvec('*.vc7')
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*
In order to import vector fields into PIVMat, you may go into the subfolder containing the VC7 files, and use v = loadvec('B00001.VC7').
However, a more convenient way is to use wildcards (*) from a parent directory of the DaVis project. For instance, in the previous example, suppose the current directory is D:\MyProjects\100121_expe. From here, you can import the VC7 files from the two directories into two PIVMat structures like this:
You can also concatenate all the files into a big PIVMat structure like this:v1 = loadvec('*Loop=1*/PIV*/*.vc7'); v2 = loadvec('*Loop=2*/PIV*/*.vc7');
You can also load the first file of each directory Loop=* like this:v = loadvec('*Loop*/PIV*/*.vc7');
See also loadarrayvec to import different files from different directories under two-dimensional structure arrays.v = loadvec('*Loop*/PIV*/B00001.vc7');
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:
You can use all Matlab ways to enumerate numbers, e.g.v = loadvec(1:10);
orv = loadvec([1 10 12:20]);
v = loadvec(100:-1:1);
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');
(note the use of curly braces {} for cell arrays of strings - see rdir for details).file = rdir('*.vc7'); for i=1:length(file) v = loadvec(file{i}); st = statf(vec2scal(v,'ken')); k(i) = st.mean; end; plot(k);
You can save your modified fields nv into standard Matlab's MAT files using the command save:v = loadvec('*Loop*/PIV*/*.vc7'); nv = filterf(medianf(rotatef(v,pi/8));
Those Matlab files may be loaded either using standard Matlab's load command or, more conveniently, directly using loadvec:save('myfields.mat','nv');
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.v = loadvec('myfields.mat');
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.vec2mat('*.vc7');
v = loadvec('*.mat');
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.
  |