Put variable valid out of loops in learnPMCode.m