Closed Nabarb closed 4 years ago
BlockObj subsref is now working as intended (I believe)
By using {} in conjunction with defaults.Shortcuts, it is possible to access directly from block elements two levels below the block hierarchy level.
default.Shortcuts
now has a new format.
default.Shortcuts
now return a struct that uses the shortcut keyword as the struct fieldname, Below that you can customize which fields to access and specify if those fields are indexable or not. See the example below.E.g. let's say you wanted to access the first 100 samples in the Raw data of the channel iCh. You would have to write:
blockObj.Channels(iCh).Raw(1:100);
With the shortcuts you configure the defaults by adding:
pars.raw.subfields = {'Channels', 'Raw'};
pars.raw.indexable = [true , true];
to the config file. Once that's done you can just call
blockObj{'raw',iCh,1:100};
You can see how the shortcut keyword is the same as the corresponding fieldname in the shortcuts struct.
Let's explore another case. Let's say you wanted to access
blockObj.Streams.DigIO(iCh).data(1:100);
You would need to add to the config file
pars.digIO.subsfield = {'Streams', 'DigIO', 'data'};
pars.digIO.indexable = [false , true , true];
Streams is a not an indexable field because is not vectorial. No () follows it.
Now by typing
blockObj{'digIO',iCh,1:100};
You will reach the same result.
blockObj.raw(iCh,1:100)
is equivalent to blockObj.Channels(iCh).Raw(1:100);
It is only available in {}, not in direct access!
blockObj{'raw',[1,2], 1:10}
will return the first ten samples from the first two channels.blockObj{'raw',[1,2],{1,[1,2]}}
gives you access from the first sample from the first channel, and the first two from the second one.The operator end is not available in shortcuts!
I've pushed some changes. Overall seems like things are working as intended. I found one bug that was potentially problematic but that's been resolved.
B = tankObj{[1,2],key};
was throwing an error due to improper arrayfun indexing of substruct argument array.nigeLab.nigelObj/getPropertyGroups
nigeLab.nigelObj/addPropListeners
checkBlocksForClones
or checkAnimalsForClones
methods. Changed syntax in listener call and that fixed it even though effectively it should be the same reference? Not sure if this is related to subsref changes yet.IsRightKeyFormat
to be a method of nigeLab.nigelObj
.
I've rewritten the subsref of tank and animal to take care of some unexpected behaviour. A Block revision will follow soon (tomorrow).
To summarize: the {} operator can be used to access the children object in the layer below or two layers below. That means that you can access blocks and animals directly from the tank level.
Classic usage
tankObj{aa}
is equivalent totankObj.Children(aa)
tankObj{aa,bb}
is equivalent totankObj.Children(aa).Children(bb)
animalObj changes it's behaviour depending on the fact that's a scalar or a vector:
animalObj{bb}
is equivalent toanimalObj.Children(bb)
;animalObj(bb,cc)
is unsupported. Issues a warning and ignores all the indexes except bb, that means that is equivalent toanimalObj.Children(bb)
.animalObj(bb)
is unsupported. Issues an error. (with one exception, more on this later)*;animalObj(aa,bb)
is equivalent toanimalObj(aa).Children(bb).
This is equivalent totankObj{aa,bb}
Advanced Indexing:
aa = [1,2]; bb = 1; tankObj{aa,bb}
will return the first block from the first two animals.aa = [1,2]; bb = [1,3]; tankObj{aa,bb}
will return the first and third block from the first two animals.aa=[1,2]; bb=key1; tankObj{aa,bb}
will look for key1 in all the blocks in animal 1 and 2.aa = [1,2]; bb={key1,key2}; tankObj{aa,bb}
will look for key1 and key2 in all the blocks in animal 1 and 2.tankObj{[1,2],{1,[1,2]}}
gives you access from the first block from the first animal, and the first two from the second one,You can also use keys.
tankObj{[1,2], {key1, {key2 key3} } }
looks for key1 between the children of animal1 and for key2 and key3 between the children of animal2.tankObj{ {keya1, keya2} , {keyb1, {keyb2 keyb3} } }
is technically supported but needs more testing and may lead to unexpected results.tankObj{ [1,2], {1, {key1 key2} } }
is not supported yet.