Can I generate matlab code from a .mat file?
4 views (last 30 days)
Show older comments
Hello
I have saved the networks I created using the nntoolbox.Its is saved as a .mat file. Is it possible for me to generate code from the same?
Thank you.
2 Comments
Answers (1)
Walter Roberson
on 17 May 2015
If you have ordinary numeric arrays that are at most 2 dimensions, then you can use mat2str(A,75) to generate a string that will rebuild the array; you can then write the string to a file. For example,
fid = fopen('mycode.m','wt');
fprintf(fid, 'A = %s;\n', mat2str(A,75));
fclose(fid);
Given any particular .mat file, code could be written to do that automatically for all numeric variables. A small extension would handle character strings.
If the code was made recursive, it would be possible to extend it to also handle struct and cell arrays of {struct, numeric, string}.
Depending on your purpose, you might be interested in the File Exchange contribution to serialize data. This has to do with constructing byte arrays that can be interpreted to rebuild the data.
0 Comments
See Also
Categories
Find more on File Operations in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!