Ovi*_*diu 2 optimization matlab matrix save 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
Run Code Online (Sandbox Code Playgroud)
这使
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
Run Code Online (Sandbox Code Playgroud)
正如你所看到的 -v6 比 -ascii 快得多
编辑:还请记住“-ascii”仅使用单精度浮点数
| 归档时间: |
|
| 查看次数: |
6366 次 |
| 最近记录: |