Complementary resistive switching mechanism in Ti-based triple TiOx/TiN/TiOx and TiOx/TiOxNy/TiOx matrix