Use older MATLAB save formats
Show older comments
I'm running a model that has a bunch of DLLs which read some .mat files.
When I use an old version of MATLAB (I think 2011a) to generate the files I get files that work okay, but when I create them with 2017a the files seem not to work with the same script.
I've used 2017 to read in the working 2011 file and then save it, and these files also don't work.
I've also tried the above with the '-vXX' settings at all available values according to the help, with no success.
Example:
clear; load('v2011file.mat'); save('v2017copy.mat', '-v6', 'var1', 'var2', 'var3');
One thing that I have notices between the two is that when they're selected in the "Current folder" browser, the preview always shows the 2017 files with the variable names in aphabetical order, regardless of the order that I saved them in, while the older 2011 file seems to maintain the order that they were saved. I can only assume that this is something related to a change in the way that files are saves - it might not be a problem but it does hint toward a change (it does this whether or not I include '-vXX' to use older formats).
It's probably worth noting that the 2011 files are created on XP, while the 2017 files are made on Windows 7.
Essentially I'm looking for anyone who might know whether it's possible for me to change the way that the file is put together by MATLAB, rather than having to change the DLLs to acceps a newer file.
6 Comments
Jan
on 12 Feb 2019
Please mention what "the files seem not to work with the same script" exactly means.
Lauren Dransfield
on 12 Feb 2019
Edited: Lauren Dransfield
on 12 Feb 2019
Rik
on 12 Feb 2019
DLL functions were replaced by mex function extentions a long time ago (R2010a and before). It was still supported for some time (although I can't find the release support ended).
What do those functions do that would change the mat file? What code are you running exactly? It seems unlikely the save function has anything to do with it, unless you are shadowing it (which you should not do).
Lauren Dransfield
on 12 Feb 2019
The "order" of variables stored in a .mat file should not be relied upon, and code that assumes that they come in a particular order is fragile code.
Having the variables in a particular "order" implies that they have some meta-data in their names (i.e. pseudo-indices), which is a slow and inefficient way to handle meta-data: much more robust would be use use actual indexing (in which case this entire problem disappears).
Lauren Dransfield
on 12 Feb 2019
Accepted Answer
More Answers (1)
Rik
on 12 Feb 2019
Since v7.3 is R2006b, I don't really see a reason why you would need to set the default to -v7.
Also, why don't you write a wrapper to replace the load? That way you remove the ordering requirement, without having to do a lot of work.
function S=loaddata(filename)
tmp=load(filename);
S=struct('var1',tmp.var1,'var2',tmp.var2,'var3',tmp.var3)
end
3 Comments
Lauren Dransfield
on 12 Feb 2019
Lauren Dransfield
on 12 Feb 2019
Rik
on 12 Feb 2019
I find it a bit strange that a dll mex function would interact with a file in the first place.
Categories
Find more on Functions 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!