text substitute for MAT files
Show older comments
Hello all:
I am debugging a large Matlab application from 2014 (tens of thousands of lines) and the previous developer used .MAT files to store data and also to pass it here and there. I think maybe he didn't understand how to pass data to callbacks, but that's neither here nor there. Somewhere the data is getting corrupted, and by a certain point in the application it is reliably wrong.
I thought of changing all the save() and load() functions to use the -ascii version to see if I could figure out when and where it goes wrong. Unfortunately, -ascii does not seem to save structs. Is anyone aware of a way to store and restore complicated (but not particularly large) Matlab variables as text?
Thank you,
-Tom
6 Comments
dpb
on 15 Feb 2019
Is this "point in the application" one in code location or in time of execution as in an iteration process?
If the former could you not insert a debug break at some point prior to that and by rough bisection be able to isolate where something seems to have gone south?
Looking at data in files even as ascii seems the hard way to debug; reminiscent of FORTRAN 77 days before source debuggers...
Tom Sgouros
on 16 Feb 2019
Walter Roberson
on 16 Feb 2019
Export to readable ASCII would be easier than import of ASCII.
Because you can have nested structures, and multidimensonial arrays, and objects with properties, it is a lot easier to create text that humans do not mind reading through, than it is to create text that MATLAB can parse to exactly recreate objects.
Now, you could use JSONlab from the file exchange to import and export structured data, but if your primary purpose is debugging then you would have to decide whether JSON is readable enough for your purpose.
Perhaps you can use conditional breakpoints to detect the characteristics of corruption. It might be after the fact, but by examining the state you might be able to work backwards.
dpb
on 16 Feb 2019
If you're still on this same path, you might consider struct2table and then writetable to do the one-way translation; I don't know that it is always reproducible to the identical structure via table2struct or not.
Tom Sgouros
on 17 Feb 2019
Answers (0)
Categories
Find more on Variables 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!