YAML 1.1 parser and emitter for MATLAB R2019b or newer. Based on SnakeYAML 1.30.
>> data.a = [1.23, 4.56];
>> data.b = {int32(2), {true, "hello", yaml.Null}};
>> s = yaml.dump(data)
"a: [1.23, 4.56]
b:
- 2
- [true, hello, null]
"
>> result = yaml.load(s)
a: {[1.2300] [4.5600]}
b: {[2] {1×3 cell}}
>> yaml.dumpFile("test.yaml", data)
>> result = yaml.loadFile("test.yaml")
a: {[1.2300] [4.5600]}
b: {[2] {1×3 cell}}
>> s = yaml.dump(data, "auto") % default
"a: [1.23, 4.56]
b:
- 2
- [true, hello, null]
"
>> s = yaml.dump(data, "block")
"a:
- 1.23
- 4.56
b:
- 2
- - true
- hello
- null
"
>> s = yaml.dump(data, "flow")
"{a: [1.23, 4.56], b: [2, [true, hello, 'null']], c: [2, [true, hola]]}
"
>> result = yaml.load("null")
Null
>> yaml.isNull(result)
1
>> s = yaml.dump(yaml.Null)
"null
"
By default, sequences are loaded as nested cell arrays to distinguish between YAML scalars and YAML one-element sequences and to supported mixed type sequences. If you use the ConvertToArray
option, sequences are converted to 1D or 2D standard arrays if possible:
>> yaml.load("[[1, 2], [3, 4]]", "ConvertToArray", true)
1 2
3 4
Since every MATLAB scalar is always an array and every array technically has at least 2 dimensions, there exists two ambiguities when dumping arrays:
To avoid theses ambiguities and get consistent conversion behaviour, convert all your array data to nested vector cells before dumping them.
>> yaml.dump({1})
"[1.0]
"
>> yaml.dump({{1, 2}})
"- [1.0, 2.0]
"