我想使用 YAML 跨多种语言交流一些数据。 (将其视为“与语言无关的序列化”。)其中一种语言是 MATLAB,但我似乎找不到该语言的 YAML 库。我在 Google 上检查了“matlab yaml”和“matlab yaml parse”,似乎没有任何相关结果。在 MATLAB Central 上搜索“yaml”也让我一无所获。
MATLAB 真的没有现有的 YAML 库吗?我很乐意写一份,但我想避免重复工作。 (也许有什么可以分享的?)
I want to use YAML to communicate some data across multiple languages. (Think of it as "language-independent serialization".) One of these languages is MATLAB, but I can't seem to find a YAML library for that language. I've checked for "matlab yaml" and "matlab yaml parse" on Google and there don't seem to be any relevant results. A search of "yaml" on MATLAB Central also left me empty-handed.
Is there really no existing YAML library for MATLAB? I'm fine with writing one, but I would like to avoid duplicating work. (Perhaps something to share?)
发布评论
评论(8)
我扩展了 Jan 的代码以支持更多数据类型以及将 matlab 结构写入 yaml 文件。它不仅仅是一个 m 文件,因此我在 http://code.google.com 上找到了源代码/p/yamlmatlab/
吉里
I extended Jan's code to support more data types as well as writing out of a matlab struct to yaml file. It is not just one m-file therefore I located the sources on http://code.google.com/p/yamlmatlab/
Jiri
从 Matlab 调用现有的 Java YAML 导入库。这应该是非常简单的。 Java-Matlab 互操作性非常好,请参阅 matlab 帮助。
Call existing Java YAML import libraries from Matlab. This should be pretty strightforward. Java-Matlab interoperability is pretty good, see matlab help.
现在有一个 Snakeyaml 的 Matlab 包装器:
http://code.google.com/p/yamlmatlab/< /a>
我已经尝试过了,它在简单的 yaml 文件上运行得很好。如果 yaml 字段名称不是有效的字段名称以及字符串为空,则会出现错误。我在谷歌代码网站的问题部分建议了这两个问题的解决方法
There is now a matlab wrapper for snakeyaml:
http://code.google.com/p/yamlmatlab/
I've tried it out and it works pretty well on a simple yaml file. There are bugs if the yaml field names are not valid fieldnames and when strings are empty. I've suggested workarounds for both of these in the issues section on the google code site
我相信,下面的例子可以节省一些时间。
首先,您需要使用 Snake YAML 加载 YAML 文档:
然后您需要从 java 对象访问数据,我使用以下例程完成它(请注意,这不是通用例程,它是为特定类型的YAML 文件,例如矩阵的定义与 Matlab 中相同)
祝你好运,
扬
I believe, that the following example can save some time.
First you need to load a YAML document using snake YAML:
and afterwards you will need to access data from the java object, I did it using the following routine (note that this is not a general routine and it was developed for a particular type of YAML files, where for example matrices are defined as in Matlab)
Good luck,
Jan
@安迪L
对于 sankeyaml,将其添加到您的 javapath,然后 import('org.yaml.snakeyaml.Yaml'),它的工作方式与文档类似;生成的 LinkedHashMap 的访问或多或少类似于 matlab 结构体。
@AndyL
For sankeyaml, add it to your javapath, then import('org.yaml.snakeyaml.Yaml'), and it works like the docs; the resulting LinkedHashMap is accessed more or less like a matlab struct.
还有 Geoffr Adams 的 MEX 实现,名为 mat-yaml,带有 C 绑定 libyaml 解析器发射器)。
但目前还不能在Windows 上编译。
There is also MEX implementation by Geoffr Adams called mat-yaml with C binding for libyaml parser-emitter).
But it can not be compiled on Windows yet.
ZozaniDB Database Toolbox 包含 YAML 的 Matlab 原生实现(以 p 文件形式分发)。
ZozaniDB Database Toolbox includes a Matlab-native implementation for YAML (distributed as p-files).
我为 SnakeYAML 编写了一个包装器:
https://www.mathworks.com/matlabcentral/fileexchange /106765-yaml
I wrote a wrapper for SnakeYAML:
https://www.mathworks.com/matlabcentral/fileexchange/106765-yaml