Resistive switching in polymer nanocomposites by matrix-controlled in situ nanoparticles generation