I'm trying to parallelize a loop in MATLAB and am getting an error which states, "Valid indices for 'X_train' are restricted in PARFOR loops." My code is below:
parfor c = 1:num_channels
% sum_n_train calculated here
for n = 1:sum_n_train
bin_n = bin(n);
Xmj = X_train(bin_n, :);
% some calculations happen in between
X_train(bin_n,:) = Xmj;
X_train(bin_n, p) = X_train(bin_n, p) + 1;
z_train(n)= zind;
end
z_train_cell{c} = z_train;
end
X_train is an n by p matrix and Xmj is a 1 by p vector. The error is for X_train. From reading the documentation, I see that the indexing for every variable must be fixed within the parfor loop. Even when I comment out the line X_train(bin_n, p) = X_train(bin_n, p) + 1; (which has a different indexing of X_train than the other two lines), however, I still get the error. Could someone please explain why and how I can work around it?
bin? Is it a function or a variable? - Bentoy13