There are several problems here, but I think the biggest problems you need to overcome is that the result of a PARFOR loop needs to be expressed as a sliced or a reduction variable, and that the iterations of the loop need to be provably order-independent. Simply put, a sliced output is one where MATLAB can see from the text of your program that each loop iteration assigns into a slice of an array, and the slice depends on the loop variable. So, the following is a sliced output:
x = zeros(10);
parfor idx = 1:10
x(:, idx) = rand(10, 1);
end
In this case, each iteration of the loop assigns into a column slice of x. In your case, the indexing expression into t1.v2 is problematic firstly because it is not a simple 'sliced' form, and secondly because the indexing expression depends on previous values in t1.v2.
You might be able to run the first expression in the loop as a PARFOR, and then perform the assignment in an ordinary FOR loop later - but this will probably not get you any improvement in performance.
parfor i = 1:size(t2,1)-1
xc{i} = find(t1.v1>t2.v1(i) & t1.v1<=t2.v1(a+1));
end
for i = 1:size(t2,1)-1
x = xc{i};
t1.v2(x(t1.v2(x)~=t2.v2(a))) = 0;
end
Best Answer