View License

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video

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

Join the 15-year community celebration.

Play games and win prizes!

» Learn more

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

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



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

| Watch this File

File Information

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.

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

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

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 <>. 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

us (view profile)

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

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

Contact us