File Exchange

image thumbnail

uneval(var_name, value, return_cell_array)

version (10.7 KB) by David Holl
Uneval performs the inverse operation of eval('expression').

1 Download

Updated 17 Jul 2015

View Version History

View License

This function converts a MATLAB variable into a text string, which when evaluated, produces the original variable having identical:
data types (single, double, int8, ...)
cell arrays
multi-dimensional arrays
nested struct's of cell arrays of structs of ...
For floating point values, enough significant digits are printed to preserve machine precision.
Contrived example usage:
settings = load('some_data.mat');
string = uneval('settings2', settings)
disp(isequalwithequalnans(settings, settings2));

This function probably does not work with handles to nested functions, figure handles, or java & OOP objects...

Cite As

David Holl (2021). uneval(var_name, value, return_cell_array) (, MATLAB Central File Exchange. Retrieved .

Comments and Ratings (6)

Chang hsiung

David Holl

Good idea, Jan! I just replaced the entire call to cellstr2string. :)

David Holl

I use this function for a few weird odds and ends.

1) One case is where I needed to create a graphical user interface to let an operator adjust some signal processing parameters on the fly.

The project grew over time, and rather than making new GUI widgets for newer but lesser used options, the GUI can present a text input field that's pre-filled in an uneval'ed structure containing every single option. The user just edits which parts they need, press OK, and then the GUI script runs eval to convert back to a usable settings structure.

2) Another case where I found this function handy is in performing "release reviews" on data sets prior to sharing with other folks. I run uneval on a given data set, and then review the resulting string in a text editor.


Just a comment: A shorter and faster version of your CELLSTR2STRING:
the_string = sprintf('%s\n', the_cellstr{:});

This is an interesting function. For what purpose do you use it?

David Holl

Sorry for the omission. I just submitted an update with the missing cell_ind2sub function.

Patrick Houweling

This function requires cell_ind2sub. Where can I get it?

MATLAB Release Compatibility
Created with R2007a
Compatible with any release
Platform Compatibility
Windows macOS Linux

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!