Slicing variable in parfor loop (restricted indexing)
Show older comments
Hello,
would somebody please know, why this code isn't sliced? Which is the problematic part. I was trying to figure it out, but unfortunately not successful.
parfor i=1:size(X,1)
for j=3:numel(r)
check = 0;
if sum(X(i,end-5:end-4)<=0) > 0 || any(isnan(X(i,end-5:end-4)))
check = 1;
end
if check == 0
X(i,j) = fn( X(i,end-1:end),...
r(j),[X(i,end-5) X(i,10)],[X(i,end-4) X(i,11)]);
end
end
end
Thanks very much in advance for any help and effort!
Accepted Answer
More Answers (1)
Steven Lord
on 3 Feb 2020
2 votes
What requirements must a variable satisfy to be a sliced variable? The documentation states four conditions:
- Type of First-Level Indexing — The first level of indexing is either parentheses, (), or braces, {}.
- Fixed Index Listing — Within the first-level parentheses or braces, the list of indices is the same for all occurrences of a given variable.
- Form of Indexing — Within the list of indices for the variable, exactly one index involves the loop variable.
- Shape of Array — The array maintains a constant shape. In assigning to a sliced variable, the right side of the assignment cannot be [] or '', because these operators attempt to delete elements.
I'm assuming you want X in your example to be the sliced variable. All the places you index into X do use parentheses, so you satisfy "Type of First-Level Indexing". Do you satisfy "Fixed Index Listing"? Here are the set of indices you use to index into X:
- (i,end-5:end-4)
- (i,end-5:end-4)
- (i,j)
- (i,end-1:end)
- (i,end-5)
- (i,10)
- (i,end-4)
- (i,11)
So no, your variable does not satisfy the "Fixed Index Listing" condition. It does satisfy "Form of Indexing" and "Shape of Array". You might be able to do something along the lines of the second example in the "Fixed Index Listing" section on that documentation page, but I haven't tried to fully understand the code you've written nor do I know what function you're using as fn so I can't be certain.
Categories
Find more on Matrix Indexing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!