The function loadvec allows to
import data into a PIVMat structure for further processing. Only importation
of data from DaVis (LaVision GmbH) files is considered in this documentation.
See the page
Data organisation in PIVMat to learn
more about PIVMat structures.
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:
v = loadvec('B00001.vc7');
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 use
v = loadvec('*.vc7')
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:
D:\MyProjects\100121_expe
Properties
Calibration.set
...
Properties.set
labbook.txt
Cam_Date=091127_Time=111140_Loop=1_dt1=20000
B00001.im7
B00001.im7
...
PIV_MP(32x32_50%ov)_PostProc
B00001.vc7
B00002.vc7
...
PIV_MP(32x32_50%ov)_PostProc.set
Cam_Date=091127_Time=111140_Loop=1_dt1=20000.set
Cam_Date=091127_Time=111718_Loop=2_dt1=20000
B00001.im7
B00001.im7
...
PIV_MP(32x32_50%ov)_PostProc
B00001.vc7
B00002.vc7
...
PIV_MP(32x32_50%ov)_PostProc.set
Cam_Date=091127_Time=111718_Loop=2_dt1=20000.set
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 files using the wildcard (*)
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:
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:
Mydata_t=0001.00s.mat
Mydata_t=0001.25s.mat
Mydata_t=0001.50s.mat
Mydata_t=0001.75s.mat
Mydata_t=0002.00s.mat
...
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');
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.