barbaLab / nigeLab

Neurophysiological data analyses by engineers, for physiologists.
GNU General Public License v3.0
14 stars 2 forks source link

Bugfix/subsref #71

Closed Nabarb closed 4 years ago

Nabarb commented 4 years ago

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,cc) is unsupported. Issues a warning and ignores all the indexes except bb, that means that is equivalent to animalObj.Children(bb).

animalObj(aa,bb) is equivalent to animalObj(aa).Children(bb). This is equivalent to tankObj{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.

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.

Nabarb commented 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.

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.

Advanced indexing.

It is only available in {}, not in direct access!

Warning

The operator end is not available in shortcuts!

m053m716 commented 4 years ago

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.


Bugfixes

Major

Minor


Updates

Notable

Minor