Code covered by the BSD License  

Highlights from
LOADFIXNAMES loads a mat file, fixing invalid names

Be the first to rate this file! 30 Downloads (last 30 days) File Size: 14 KB File ID: #42274
image thumbnail

LOADFIXNAMES loads a mat file, fixing invalid names

by

 

18 Jun 2013 (Updated )

Loads a mat file into the caller's workspace, fixing invalid variable and field names.

| Watch this File

File Information
Description

Building:

LOADFIXNAMES is typically self building. That is, the first time you call it, the loadfixnames.m file recognizes that the mex routine needs to be compiled and then the compilation will happen automatically.

The usage is as follows (arguments in brackets [ ] are optional):

Syntax

loadfixnames(FILENAME [,names] [,verbose])
S = loadfixnames(FILENAME [,names] [,verbose])

     FILENAME = The mat file to be loaded
     names = string or cell array of strings (variable name(s) to load)
     verbose = 1 or 0 (optional, causes name change log to be displayed)
     S = struct returned instead of loading variables into workspace

 Description

LOADFIXNAMES loads a mat file into the workspace, fixing invalid names. All invalid characters are replaced with an underscore. Also, if the first character is not a letter, an 'A' is added to the front. If the variable is a structure, fixes the field names also. In the case of field names, the name length is kept constant. So if a field name begins with a digit it will be replaced with 'A' - 'J' instead. If the field name begins with an invalid non-digit it will be replaced with 'A' - 'Z' or 'a' - 'z' (letters are cycled in an attempt to avoid name clashes).

Limitations: The current renaming scheme makes a mild attempt to avoid name clashes, but does not guarantee this.

See the companion function SAVEBADNAMES for a test function that will intentionally create a mat file with invalid names.

Building:

SAVEBADNAMES is typically self building. That is, the first time you call it, the savebadnames.m file recognizes that the mex routine needs to be compiled and then the compilation will happen automatically.

The usage is as follows (arguments in brackets [ ] are optional):

Syntax

savebadnames(FILENAME [,verbose])

    FILENAME = The mat file to be saved
    verbose = 1 or 0 (optional, causes name change log to be displayed)

Description

SAVEBADNAMES saves a mat file using intentionally invalid names.

MATLAB release MATLAB 7.3 (R2006b)
Other requirements Any C compiler, such as the supplied LCC compiler. The routines are self-building ... you don't have to know anything about mex or C to use them.
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (1)
18 Jun 2013 James Tursa

NOTE: The supplied SAVEBADNAMES function only works for older versions of MATLAB (I think R2006a and earlier). After that TMW fixed the matPutVariable function so that it does not accept invalid names when writing to a mat file.

Updates
30 Oct 2013

Added code to deal with duplicate variable names

Added capability to return a struct

Contact us