the @key class dot-properties
let's assume k
, a @key object created from the following sample keyfile
:
label start finish cues conds resps red_vert -100 200 23 [1:5 100] 0 % this is a comment red_horiz -100 200 25 11:20 0 blue_vert -100 200 23 21:30 0 blue_vert -100 200 25 31:40 0
you can retrieve information from the object using the following notation:
>> object.property
note that only the first 3 letters (case-insensitive) of the property name are meaningful. Thus, the following sample calls are equivalent:
>> k.con; >> k.conditions; >> k.Conds;
getting information on the object as a whole
>> k.print % lists the object's content on the command window >> k.length % returns the number of keys in the object >> k.size % returns the number of subkeys for each key ans = 1 1 2 >> k.labels ans = 'red_vert' 'red_horiz' 'blue_vert'
returning a single-key object from an existing object
individual keys from a @key object can be referenced by either the key number or the key label, in parentheses:
>> k2 = k(2); >> k3 = k('blue_vert'); % note that k(3) is a complex key >> k3.size % the key has 2 subkeys ans = 2 >> k4 = k(3,2); return only the 2nd subkey of the 3rd key >> k4.size ans = 1
returning specific fields from a key
to retrieve field values from a single key, append a dot followed by the field name:
>> k(1).label ans = 'red_vert' >> k('red_vert').conditions ans = 1 2 3 4 5 100
careful about complex keys:
>> k(3).cues Warning: this is a complex key; returning value for 1st subkey only > In c:\users\giuseppe\docs\matlab\giucode\@key\subsref.m at line 135 ans = 23 >> k('blue_vert',2).cues % requesting the cue code for the 2nd subkey of k(3) ans = 25
again note that key number and key label are interchangeable indexing methods.
changing field values
Values of individual key fields can be set in the following way:
>> k(2).resps = [0,6]; >> k(1).label = 'different_name';
Careful about complex keys:
>> k(3).blocks = [4 5]; ??? Error using ==> key/subsasgn this is a complex key try: kobj(key,subkey).field=value >> k(3,1).blocks = [4 5]; >> k(3,2).blocks = [4 5]; % this will work