Load single variable from MAT-file, and save variable to existing MAT-file.
Syntax
variable = loadvar(matfile,varname)
savevar(matfile,varname)
savevar(matfile,varname,varvalue)
Description
loadvar loads a single variable from a MAT-file and assigns its value to a variable. The name of the file is given in the string matfile, the name of the variable in the string varname.
savevar saves a single variable to an already existing MAT-file. The value of the variable is given in varvalue. varvalue may be any valid expression in MATLAB. If varvalue is not given, the variable will be deleted from the MAT-file.
If no extension is given, the default extension (.mat) is appended to the filename.
The MAT-file should be in the active subdirectory/folder if savevar is used, or the path has to be explicitly given.
Note: using savevar, the variable donotusethisnamemf will also appear in the MAT-file, with the name of the file as string value.
Examples
The value of a variable can be checked easily without destroying the complete workspace by loading the complete binary file
itlimit = loadvar('inpchans.ebn','itmax')
The value of a variable in a previously saved workspace can be changed,
and/or a new variable can be added to the saved workspace:
x = 1; save savevtst.mat x
savevar('savevtst.mat','x',10)
savevar('savevtst.mat','y',20)
Algorithm
Both loadvar and savevar are function M-files, which assign the input arguments to hopefully not used long variable names (donotusethisnamev, donotusethisnamevv), load the MATLAB binary file, and create the desired variable. savevar also saves the MAT-file again. loadvar and savevar will behave in an unpredictable way when either of these two long variable names are used in the MAT-file.
[ Previous | Help Desk | Next ]