User`s guide
2 Parallel for-Loops (parfor)
2-28
After the first level, you can use any type of valid MATLAB indexing in the second and
further levels.
The variable A shown here on the left is not sliced; that shown on the right is sliced:
A.q{i,12} A{i,12}.q
Fixed Index Listing. Within the first-level parentheses or braces of a sliced variable’s
indexing, the list of indices is the same for all occurrences of a given variable.
The variable A shown here on the left is not sliced because A is indexed by i and i+1 in
different places; the code on the right shown on the right slices A:
Not sliced Sliced
parfor i = 1:k
B(:) = h(A(i), A(i+1));
end
parfor i = 1:k
B(:) = f(A(i));
C(:) = g(A{i});
end
The example above on the right shows some occurrences of a sliced variable with first-
level parenthesis indexing and with first-level brace indexing in the same loop. This is
acceptable.
The following example on the left does not slice A because the indexing of A is not the
same in all places. The example on the right slices A and B. The indexing of A is not the
same as the indexing of B, but all indexing of A is consistent, and all indexing of B is
consistent.
Not sliced Sliced
parfor i=1:10
b = A(1,i) + A(2,i)
end
A = [ 1 2 3 4 5 6 7 8 9 10;
10 20 30 40 50 60 70 80 90 100];
B = zeros(1,10);
parfor i=1:10
for n=1:2
B(i) = B(i)+A(n,i)
end
end
Form of Indexing. Within the list of indices for a sliced variable, one of these indices is
of the form i, i+k, i-k, k+i, or k-i, where i is the loop variable and k is a constant or