The OP said that the Ai are psd, so should have
variable A(p,p,n) semidefinite
instead of
variable A(p,p,n) symmetric
which eliminates the need for the additional line
A == semidefinite([p,p,n])
See mcg’s answer in Creating Dynamic Variables with Constraints (avoid for loop) .