image thumbnail

uneval(var_name, value, return_cell_array)

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

1.3K Downloads

Updated 17 Jul 2015

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, ...)
structures
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)
eval(string);
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) (https://www.mathworks.com/matlabcentral/fileexchange/19953-uneval-var_name-value-return_cell_array), MATLAB Central File Exchange. Retrieved .

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!