MATLAB: Can I control the column order of workspace variables saved to .mat format

columnsexportimportmatorderoriginoriginlabssave

I would like to save workspace variables to a .mat file and then open them up in Origin. Is there a way to control the order in which the variables appear in Origin's columns? Alternatively, how does MATLAB choose the column order when saving workspace variables? The variables (all vectors) I'm using have a variety of naming patterns and sizes (1 to 10,000 rows). I haven't found a reliable scheme as to how MATLAB orders these variables.
An example of the code I'm using is listed below:
SampleData_1 = (1:200)';
SampleData_2 = (1:2:200)';
SampleData_3 = (1:10:5000)';
save 'ExportTest.mat' SampleData_1 SampleData_2 SampleData_3;
After importing ExportTest.mat into Origin, the following variables appear from left to right: SampleData_1, SampleData_2 and SampleData_3. Can I force it to appear from left to right: SampleData_3, SampleData_1 and SampleData_2?

Best Answer

Undocumented behavior. Can't rely on anything about the internal order; all SAVE says is that can LOAD the file back and have what was stored returned. A test here of some local variables of
save file1.mat a b
save file2.mat b a
!fc /b file1.mat file2.mat
showed the only difference internally was the three positions in the internal header that record the timestamp--iow, internally Matlab wrote the two variables in the same order regardless of the order they were on the command line.
OTOH,
save file1.mat a
save file1.mat b -append
save file2.mat b
save file2.mat a -append
shows that the two files are different. This version probably works albeit even it would be relying on undocumented behavior.
Why don't you just write stream files with fprintf where you know you can control the content and order?
ERRATUM:
"...write stream files with fprintf ..."
That is/was intended to be fwrite of course... :(
Related Question