在matlab问题中读取.yml文件

时间:2015-07-20 11:07:11

标签: matlab file-io yaml

对于我的项目,我想使用YAMLMatlab在matlab中读取yml文件。我的.yml文件看起来像这样。我正在展示.yml文件的一部分。我的文件大约29 MB。

%YAML:1.0
Block size: [ 16, 16 ]
Block stride: [ 8, 8 ]
Cell size: [ 8, 8 ]
block hist size: 36
block per img: [ 63, 63 ]
Total elements in array: 142884
nbins: 9
Scale: 1.
Level: 0
Width: 512
Height: 512
features:
   - 1.5302167832851410e-01
   - 1.0552208870649338e-01
   - 1.6659785807132721e-01
   - 2.3539969325065613e-01
   - 2.0810306072235107e-01
   - 1.2627227604389191e-01
   - 8.0759152770042419e-02
   - 6.4930714666843414e-02
   - 6.1364557594060898e-02
   - 2.1614919602870941e-01
   - 1.4714729785919189e-01

在阅读.yml文件时,我收到以下错误。

Error using ReadYamlRaw>load_yaml (line 78)
Java exception occurred:
java.lang.OutOfMemoryError: Java heap space
    at java.util.Arrays.copyOf(Unknown Source)
    at java.lang.AbstractStringBuilder.expandCapacity(Unknown Source)
    at java.lang.AbstractStringBuilder.ensureCapacityInternal(Unknown Source)
    at java.lang.AbstractStringBuilder.append(Unknown Source)
    at java.lang.StringBuilder.append(Unknown Source)
    at org.yaml.snakeyaml.reader.StreamReader.<init>(StreamReader.java:51)
    at org.yaml.snakeyaml.Yaml.load(Yaml.java:399)

Error in ReadYamlRaw (line 42)
    result = load_yaml(filename, nosuchfileaction, treatasdata);


Error in ReadYaml (line 48)
    ry = ReadYamlRaw(filename, 0, nosuchfileaction, treatasdata);


Error in untitled (line 2)
 YamlStruct = ReadYaml(yaml_file);

我认为这个错误是由于文件大,因为我可以阅读简单的.yml文件。有人可以帮我解决这个错误。我也读过这个post

P.S:Here是.yml文件

修改
它适用于以下答案,但我现在得到以下错误。一旦我卸妆%YAML:1.0。它工作正常。

Error using ReadYamlRaw>load_yaml (line 78)
Java exception occurred:
while scanning a directive
 in "<string>", line 1, column 1:
    %YAML:1.0
    ^
expected alphabetic or numeric character, but found :(58)
 in "<string>", line 1, column 6:
    %YAML:1.0
         ^

    at org.yaml.snakeyaml.scanner.ScannerImpl.scanDirectiveName(ScannerImpl.java:1028)
    at org.yaml.snakeyaml.scanner.ScannerImpl.scanDirective(ScannerImpl.java:990)
    at org.yaml.snakeyaml.scanner.ScannerImpl.fetchDirective(ScannerImpl.java:534)
    at org.yaml.snakeyaml.scanner.ScannerImpl.fetchMoreTokens(ScannerImpl.java:251)
    at org.yaml.snakeyaml.scanner.ScannerImpl.checkToken(ScannerImpl.java:179)
    at org.yaml.snakeyaml.parser.ParserImpl$ParseImplicitDocumentStart.produce(ParserImpl.java:198)
    at org.yaml.snakeyaml.parser.ParserImpl.peekEvent(ParserImpl.java:161)
    at org.yaml.snakeyaml.parser.ParserImpl.checkEvent(ParserImpl.java:146)
    at org.yaml.snakeyaml.composer.Composer.getSingleNode(Composer.java:105)
    at org.yaml.snakeyaml.constructor.BaseConstructor.getSingleData(BaseConstructor.java:121)
    at org.yaml.snakeyaml.Yaml.loadFromReader(Yaml.java:480)
    at org.yaml.snakeyaml.Yaml.load(Yaml.java:399)

Error in ReadYamlRaw (line 42)
    result = load_yaml(filename, nosuchfileaction, treatasdata);


Error in ReadYaml (line 48)
    ry = ReadYamlRaw(filename, 0, nosuchfileaction, treatasdata);


Error in untitled (line 2)
 YamlStruct = ReadYaml(yaml_file);

1 个答案:

答案 0 :(得分:3)

在MATLAB中,从菜单/ toolstrip中选择Preferences。找到MATLAB&gt; General&gt; Java Heap Memory部分,并增加Java堆大小。

更改此设置后,您需要重新启动MATLAB才能生效。