Encode

From Eigenvector Research Documentation Wiki
Jump to navigation Jump to search

Purpose

Translates a variable into MATLAB executable code.

Synopsis

str = encode(item,varname)
str = encode(item,varname,varindex,options)

Description

The created code can be eval'd or included in an m-file to reproduce the variable. This is essentially an inverse function of "eval" for variables.

Input is a variable (item) and an optional name for that variable (varname). If (varname) is omitted, the input variable name will be used. If varname is empty, leading code which does assignment is omitted.

Output is a string (str) which can be inserted into an m-file or passed to eval for execution.

Inputs

  • item = variable to be recreated by executable code

Optional Inputs

  • varname = name for variable to be created by executable code
  • varindex = an internal index number used for struct and cell assignments when multiple layers of complex variable types are detected
  • options = a structure with one or more of the fields identified below.

Outputs

  • str = output string with executable code

Options

  • max_array_size : [10000] Maximum size allowed for any array dimension. Arrays with any size larger than this will be returned as simply [NaN]
  • structformat : [ 'struct' | {'dot'} ] defines how structures are encoded. 'struct' uses a "struct('a',val)" style (but can get very complex with large structures). 'dot' uses "x.a = val" format which is easier to read, but less compact.
  • forceoneline : [ {'off'} | 'on' ] remove all line breaks and ellipses from output. WARNING: this can cause a VERY long line on big objects and may exceed the maximum line length of editors or even MATLAB.
  • includeclear : [ {'on'} | 'off'] use 'clear' commands before assignment statements (may be required to avoid warnings when existing variables are replaced).
  • compression : [ 'format' | 'speed' |{'runs'}] defines how to compress the display of numeric values.
  • 'format' identifies the most compact format for each given number. The most compact form for arrays of mixed floating point and integer values, but slow.
  • 'speed' identifies the most compact format for groups of numbers and provides the fastest conversion. Vectors with mixed integer and floating point will be less compact in size.
  • 'runs' identifies runs of numbers and compresses them using Matlab's colon notation. Also compresses groups of identicial numbers. Best format for vectors and arrays with repeating numbers and linearly increasing or decreasing series. Intermediate in speed.
  • floatdigits : [ 12 ] number of digits to show in floating point numbers.
  • wrappedobject : [ {'off'} | 'on' ] indicates when the item being passed is an object wrapped in a cell array in order to "hide" it from the overloaded method. When 'on', encode will strip the object out of the cell before encoding it recursively. This approach allows all the input logic to reside here.

Example

Create code to reproduce a preprocessing structure

  >> p = preprocess('default','meancenter');
  >> encode(p)

See Also

encodexml, parsexml