Save/load八度大矩阵

Save/load a large matrix in Octave

我正在 Octave 中处理大量点云数据(不同的文件范围从 [10^5 到 10^7, 4] 个元素),我正在寻找优化代码的方法。

现在我正在尝试将数据保存到 .mat 文件中,因为我在某处读到(需要确认)从 .mat 文件加载比每次加载实际的 data.txt 文件。

save -ascii myfile data 可以很好地满足需求,因为它只是我想存储的数值,但是

load('myfile.mat') 调出一个包含所有值的 1x1 矩阵,而不是 nx4 矩阵,这很奇怪,因为当我使用 load('data.txt') 时,我得到了一个完整的 nx4 矩阵。

问题似乎与 save 语法有关。有什么方法可以保存文件,以便我可以使用其原始尺寸加载它?还是我必须以某种方式操纵生成的 1x1 变量?

奖金问题:
浏览一些答案,我觉得使用转置矩阵而不是 nx4 会大大改善运行时间。真的吗?

如果速度很重要,请使用二进制格式。下面稍微比较一下速度

a = rand (1e6, 4);
fn = tmpnam;

tic; save ("-ascii", fn, "a"); toc;
tic; load ("-ascii", fn); toc;
stat (fn).size

tic; save ("-v7", fn, "a"); toc;
tic; load ("-v7", fn); toc;
stat (fn).size

tic; save ("-v6", fn, "a"); toc;
tic; load ("-v6", fn); toc;
stat (fn).size

tic; save ("-binary", fn, "a"); toc;
tic; load ("-binary", fn); toc;
stat (fn).size

这给出了

Elapsed time is 2.82237 seconds.
Elapsed time is 6.28686 seconds.
ans =  61000000
Elapsed time is 1.54074 seconds.
Elapsed time is 0.252718 seconds.
ans =  30192558
Elapsed time is 0.030833 seconds.
Elapsed time is 0.047183 seconds.
ans =  32000184
Elapsed time is 0.116342 seconds.
Elapsed time is 0.0523431 seconds.
ans =  32000045

如您所见,-v6 比 -ascii 快得多

编辑:还要记住“-ascii”只使用单精度浮点数