In Matlab or GNU Octave I’d like to do something like this:
x=struct('a',1,'b',2,'c',[1 2;3 4])
y=x(:) % array-ification of a struct
save -ascii y.txt y
z=load('y.txt')
x(:)=z % struct-ification of an array
I want to serialize/pickle a structure and recreate it later, allowing easy read/save/manipulate in other languages. I’d prefer the intermediate form to be ascii text rather than binary to facilitate human reading/editing/debugging.
Am I forgetting some clever (:)-like slicing for structs or cell arrays?
I think what you want is something like:
But I do not think you can easily recreate it from the resulting file: there is data loss (the fieldnames are lost). If you don’t use the -ascii option, it can be fully recreated using:
Additionally load can only load a rectangular array of numbers of ASCII text (see http://www.mathworks.com/help/techdoc/ref/save.html and http://www.mathworks.com/help/techdoc/ref/load.html for the limitations). If you wish to keep the fields of the struct in your serialized form, you might look into the “fieldnames” function.