4.0

4.0 | 1 rating Rate this file 11 Downloads (last 30 days) File Size: 2.08 KB File ID: #24201
image thumbnail

class2str: creates an eval-able string containing Matlab code describing a variable

by

 

Creates an eval-like string which represents a variable. Useful for saving data/INI configuration

| Watch this File

File Information
Description

class2str(this,data) Create a string [ 'this = data;' ]
    This function creates a string containing Matlab code describing a variable. Works recursively, for any class type (char, struct, cell, array, objects, ...). First argument may be omitted, so that class2str(variable) will also work. String can then be exported into a file.

INPUT
this: string containing the name of the object to describe (optional)
data: any data set (struct, array, cell, char)

OUTPUT
str: string which contains a code to generate the data.

EXAMPLES:
str=class2str('this', struct('a',1,'b',{'a comment'},'c',{[]}) );
str=class2str(struct('a',1,'b',{'a comment'},'c',{[]}));

See also: mat2str, num2str, eval, sprintf

 
  Part of: iFiles utilities (ILL library)
  Author: E. Farhi <farhi@ill.fr>. June, 2007.

MATLAB release MATLAB 6.5 (R13)
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (1)
19 May 2009 us

nice and useful utility... given the release for which it was coded (r13)

unfortunately, it does not (yet!) too well for more modern data types:
- function handles are recognized and it ends with a error msg
- graphics handles, eg, gca/line/etc, are caught by
their current value
- other classes are decoded into a struct, which may not
completely reconstruct the object, eg,
c=cfit; % <- a fit object
ends up as
res=struct(c);

some of these (understandable) shortcomings should be mentioned in the help section...
us

Contact us