"Error using reshape"

This will work for p =1 or p = 2. Otherwise, you will need to reformulate per my 2nd answer at Minimizing sum of powers .