如何加载matlab矩阵与犰狳? [英] how to load matlab matrix with armadillo?

查看:357
本文介绍了如何加载matlab矩阵与犰狳?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道matlab矩阵可以加载到C ++程序在某些方面,而这些方法似乎没有一个是高效或方便。
我看到其他人修改了'.mat'文件的头部,然后它可以直接加载到带有armadillo的C ++程序中。

I know matlab matrix can be loaded into C++ program in some ways, while none of these ways seem to be efficient or convenient. I have seen others modified the header of the '.mat' file, then it can be directly loaded into C++ program with armadillo.

这不只是保存matlab'.mat'文件转换为ascii格式。加载时间和存储空间大于二进制格式。
要存储一个2GB的二进制mat文件,我需要至少20GB以ASCII格式存储它。
加载100MB二进制mat文件需要不到1秒,加载相同大小的ASCII文本数据需要更长的时间。

It's not just save the matlab '.mat' file into ascii format. The loading time and storage space is larger than binary format. To store a 2GB binary mat file, I need at least 20GB to store it in ASCII format. Loading 100MB binary mat file takes less than 1 second, load same size ASCII text data takes much longer.

我不认为将matlab mat文件保存为ASCII格式,并将其加载到armadillo是一个很好的解决方案。

I don't think save the matlab mat file into ASCII format and load it into armadillo is a good solution.

推荐答案

根据 Armadillo文档


file_type可以是以下之一:

。 。

raw_ascii:

以原始ASCII格式存储的数值数据,不带标题。数字由空格分隔。每行中的列数必须相同。立方体作为一个切片加载。使用-ascii选项保存在Matlab / Octave中的数据可以在Armadillo中读取,除了复数。复数以标准C ++表示法存储,这是由括号包围的元组:例如。 (1.23,4.56)表示1.24 + 4.56i。

file_type can be one of the following:
...
raw_ascii:
Numerical data stored in raw ASCII format, without a header. The numbers are separated by whitespace. The number of columns must be the same in each row. Cubes are loaded as one slice. Data which was saved in Matlab/Octave using the -ascii option can be read in Armadillo, except for complex numbers. Complex numbers are stored in standard C++ notation, which is a tuple surrounded by brackets: eg. (1.23,4.56) indicates 1.24 + 4.56i.

因此,您应该能够加载以文本格式写入的Matlab矩阵,包含在名为MatlabMatrix.mat使用以下代码:

You should therefore be able to load a Matlab matrix written in text format, contained in a file called "MatlabMatrix.mat", by using the following code:

arma::mat fromMatlab;
fromMatlab.load("MatlabMatrix.mat", arma::raw_ascii);

此外,还可以找到相关问题此处

Also, a related question can be found here.

这篇关于如何加载matlab矩阵与犰狳?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆