Encode: Difference between revisions
Jump to navigation
Jump to search
imported>Jeremy (Importing text file) |
imported>Bob No edit summary |
||
Line 1: | Line 1: | ||
===Purpose=== | ===Purpose=== | ||
Translates a variable into | Translates a variable into MATLAB executable code. | ||
===Synopsis=== | ===Synopsis=== | ||
Line 8: | Line 7: | ||
:str = encode(item,varname) | :str = encode(item,varname) | ||
:str = encode(item,varname,options) | :str = encode(item,varname,varindex,options) | ||
===Description=== | ===Description=== | ||
Line 17: | Line 16: | ||
Output is a string (str) which can be inserted into an m-file or passed to eval for execution. | 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 | |||
====Outputs==== | |||
* '''str''': output string with executable code | |||
===Options=== | ===Options=== | ||
Line 25: | Line 37: | ||
* '''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. | * '''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). | |||
'''Example''' | '''Example''' | ||
Line 30: | Line 44: | ||
Create code to reproduce a preprocessing structure | Create code to reproduce a preprocessing structure | ||
>> p = preprocess('default','meancenter'); | <pre> | ||
>> p = preprocess('default','meancenter'); | |||
>> encode(p) | >> encode(p) | ||
</pre> | |||
===See Also=== | ===See Also=== | ||
[[encodexml]], [[parsexml]] | [[encodexml]], [[parsexml]] |
Revision as of 18:41, 8 October 2008
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
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).
Example
Create code to reproduce a preprocessing structure
>> p = preprocess('default','meancenter'); >> encode(p)