code: def _todict(matobj):
      
      dictionary = {}
      #noinspection PyProtectedMember
      for strg in matobj._fieldnames:
          elem = matobj.__dict__[strg]
          if isinstance(elem, matlab.mio5_params.mat_struct):
              dictionary[strg] = _todict(elem)
          else:
              dictionary[strg] = elem
      return dictionary
docs: a recursive function which constructs from matobjects nested dictionaries