yaml.load()

result = load(s, options)

Parse a YAML string into MATLAB data types.

  • result = yaml.load(s) parses the YAML document contained in the string s and converts it into MATLAB data types.

  • result = yaml.load(s, options) allows control over the conversion behavior using name-value options.

Parameters

  • s (string) — YAML document to be parsed, provided as a string.

  • options.ConvertToArray (logical, default = false) — If true, YAML sequences are converted to non-cell MATLAB arrays whenever possible. For example, result = yaml.load(s, 'ConvertToArray', true) or result = yaml.load(s, ConvertToArray=true).

Returns

  • result (struct, array, cell or scalar) - MATLAB representation of the parsed YAML document, with types inferred from the YAML content.

YAML-MATLAB data conversion

The following table summarizes the mapping from YAML types to MATLAB types:

YAML type

MATLAB type

Sequence

cell (or array if ConvertToArray = true)

Mapping

struct

Floating-point number

double

Integer

double

Boolean

logical

String

string

Date (yyyy-mm-ddTHH:MM:SS)

datetime

Date (yyyy-mm-dd)

datetime

null

0-by-0 double

Examples

>> str = "{a: 1, b: [text, false]}";
>> result = yaml.load(str)

struct with fields:
  a: 1
  b: {["text"]  [0]}