In MATLAB how do I save a structure array to a text file so that it displays everything the structure array shows in the command window?
相关问题
- Extract matrix elements using a vector of column i
- How to get the maximum of more than 2 numbers in V
- Faster loop: foreach vs some (performance of jsper
- Convert Array to custom object list c#
- pick a random item from a javascript array
相关文章
- Numpy matrix of coordinates
- PHP: Can an array have an array as a key in a key-
- Accessing an array element when returning from a f
- How can I convert a PHP function's parameter l
- How to make a custom list deserializer in Gson?
- How do I append metadata to an image in Matlab?
- Recursively replace keys in an array
- React Native - Dynamic Image Source
To convert any data type to a character vector as displayed in the MATLAB command window, use the function
You can then write the contents to a file
I know this thread is old but I hope it's still going to help someone:
I think this is an shorter solution (with the constraint that each struct field can contain scalar,arrays or strings):
Now your struct array is stored in the data.csv file. The column names are the field names of a struct and the rows are the different single-structs of your struct-array
Use fprintf
You have to define a format for your file first.
Saving to a MATLAB workspace file (.MAT)
If you don't care about the format, and simply want to be able to load the data at a later time, use
save
, for example:That stores struct array
structarr
in a binary MAT file named "file.mat". To read it back into your workspace you can useload
:Saving as comma-separated values (.CSV)
If you want to save your struct array in a text file as comma-separated value pairs, where each pair contains the field name and its value, you can something along these lines:
This solution assumes that each field contains a scalar value or a string, but you can extend it as you see fit, of course.