All,
With the help of Walter's answer I have figured out the correct way to create this parallel loop structure and will report it here in case anyone is having a similar issue. However, Matt's answer here is actually a much better solution to this problem (and is actually how I am now implementing this section of code now) so if you are having a similar issue, consider if you can adopt Matt's advice instead.
Here is the full answer. The issue had to deal with both what Walter pointed out with the indexing, and with the way MX was being used. If we instead write
MX2 = zeros(6,1);
parfor f = 1:6
MX3 = zeros(q^2,1);
for j = 1:q
for i = 1:q
ind = (j-1)*q+i;
V = vec(:,i,j,f)-vec(:,i+1,j+1,f);
V2 = vec(:,i+1,j,f)-vec(:,i,j+1,f);
MX3(ind) = max([norm(V),norm(V2)]);
end
end
MX2(f) = max([MX3;0]);
end
MX2 = max(MX2)^2;
then the parallel loop works. Note that we had to define a new temporary variable here, MX3, in order to get things to work. As Matt mentions, we can create a situation without the temporary variable MX3 where everything would theoretically work; however, because of the way things are defined and indexed MATLAB's parfor checker will still throw an error.
Anyway, I hope this helps anyone who is having a similar issue with parallel processing.