In Matlab, one can evaluate an arbitrary string as code using the eval
function. E.g.
s = '{1, 2, ''hello''}' % char
c = eval(s) % cell
Is there any way to do the inverse operation; getting the literal string representation of an arbitrary variable? That is, recover s
from c
?
Something like
s = repr(c)
Such a repr
function is built into Python, but I've not come across anything like it in Matlab, nor do I see a clear way of how to implement it myself.
The closest thing I know of is something like disp(c)
which prints out a representation of c
, but in a "readable" format as opposed to a literal code format.