Reputation: 222
I have a large variable stored in a mat file and in a .m file. The data is just a big cell:
Tensor{1,1,1,1,1,1,1,1,1,1,1,1}=[1,1,2,2,1, (... )];
Tensor{1,1,1,1,1,1,1,1,1,1,1,2}=[1,1,2,2,3, (... )];
(...)
Why it is so much slower to load the variable form the mat-file, than from the m-file?
tic;load('Tensor.mat');toc
Elapsed time is 6.969654 seconds.
tic;Tensor;toc
Elapsed time is 0.152476 seconds.
Is there a way to save variables as m-files?
@Daniel An example of a typical entry is:
Tensor{2,2,2,2,2,4,4,4,4,4,4,4} = [ ...
0,0,0,0,0,(1 / 6) .* 22 .^ (-1 / 2),0,0,0,0,0,0,0 ; ...
0,0,0,0,(1 / 6) .* ( 5 / 33) .^ (1 / 2),0,(-1 / 12) .* (7 / 11) .^ (1 / 2),0,0,0,0,0,0 ; ...
0,0,0, (1 / 11) .* (5 / 6) .^ (1 / 2),0,(-35 / 132) .* 3 .^ (-1 / 2),0,(7 / 44) .* 3 .^ (-1 / 2),0,0,0,0,0; ...
0,0,(1 / 11) .* (5 / 6) .^ (1 / 2),0,(-7 / 33),0,(1 / 44) .* 105 .^ (1 / 2),0,(-7 / 66),0,0,0,0; ...
0,(1 / 6) .* (5 / 33) .^ (1 / 2),0,(-7 / 33),0,(7 / 33) .* (5 / 2) .^ (1 / 2),0,(-35 / 198) .* (5 / 2) .^ (1 / 2),0,(7 / 66),0,0,0; ...
(1 / 6) .* 22 .^ (-1 / 2),0,(-35 / 132) .* 3 .^ (-1 / 2),0,(7 / 33) .* (5 / 2) .^ (1 / 2),0,(-25 / 66) .* (7 / 6) .^ (1 / 2),0,(35 / 198) .* (5 / 2) .^ (1 / 2),0,(-7 / 44) .* 3 .^ (-1 / 2),0,0; ...
0,(-1 / 12) .* (7 / 11) .^ (1 / 2),0,(1 / 44) .* 105 .^ (1 / 2),0,(-25 / 66) .* (7 / 6) .^ (1 / 2),0,(25 / 66) .* (7 / 6) .^ (1 / 2),0,(-1 / 44) .* 105 .^ (1 / 2),0,(1 / 12) .* (7 / 11) .^ (1 / 2),0; ...
0,0,(7 / 44) .* 3 .^ (-1 / 2),0,(-35 / 198) .* (5 / 2) .^ (1 / 2) ,0,(25 / 66) .* (7 / 6) .^ (1 / 2),0,(-7 / 33) .* (5 / 2) .^ (1 / 2),0,( 35 / 132) .* 3 .^ (-1 / 2),0,(-1 / 6) .* 22 .^ (-1 / 2); ...
0,0,0,(-7 / 66), 0,(35 / 198) .* (5 / 2) .^ (1 / 2),0,(-7 / 33) .* (5 / 2) .^ (1 / 2),0,( 7 / 33),0,(-1 / 6) .* (5 / 33) .^ (1 / 2),0; ...
0,0,0,0,(7 / 66),0,(-1 / 44) .* 105 .^ (1 / 2),0,(7 / 33),0,(-1 / 11) .* (5 / 6) .^ (1 / 2),0,0; ...
0,0,0,0,0,(-7 / 44) .* 3 .^ (-1 / 2),0,(35 / 132) .* 3 .^ (-1 / 2),0,(-1 / 11) .* (5 / 6) .^ (1 / 2),0,0,0; ...
0,0,0,0,0,0,(1 / 12) .* (7 / 11) .^ (1 / 2),0,(-1 / 6) .* (5 / 33) .^ (1 / 2),0,0,0,0; ...
0,0,0,0,0,0,0,(-1 / 6) .* 22 .^ (-1 / 2),0,0,0,0,0 ...
] ;
Upvotes: 3
Views: 156
Reputation: 3832
That is because the .mat-file is a binary file that requires some processing to extract a variable, while the .m-file is nothing else just a text file. Instead of .m-file it is more convenient to save data in .dat-file. The result should be about the same. This can be checked trying these two commands:
tic;load('Tensor.mat');toc
tic;load('Tensor.dat','-ascii');toc
Upvotes: 1