Thanks!
I just tested it, it could save ~50% time when building constraints, but the time still look quadratically increasing though.
Unfortunately my matrix A is dense and large, but the 3rd dim could be redundant since they are similar. This could be improved.
Similarly, if my x variable is a 3d matrix: x = sdpvar(n,n,m); I can defined a 2d cell array X so that X{i,j} is the same as x(:,i,j)...I guess this could save more time since it reduces redundant subsrefs:ing. But it turns out to be more time consuming..., see the figure below:

I did save time when constructing constr, but I wasted more time when creating the cell array....how to efficiently create a multi-dimensional sdpvar cell array?
Currently this is what I'm doing: