How to use parfor
3 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
The original code is as follows, which I would like to convert to parallel using "parfor"
for rownum=1:rows
for size=1:half
flip=cols-size+1 o1=original(rownum,flip,1);
o2=original(rownum,flip,2);
o3=original(rownum,flip,3);
original(rownum,flip,1)=original(rownum,size,1);
original(rownum,flip,2)=original(rownum,size,2);
original(rownum,flip,3)=original(rownum,size,3); original(rownum,size,1)=o1;
original(rownum,size,2)=o2;
original(rownum,size,3)=o3;
end
endHelp needed, Thanks in advance.
0 commentaires
Réponses (1)
OCDER
le 6 Juin 2018
Are you trying to flip the matrix along the 2nd dimension?
original = flip(original, 2)
Can't do parfor in your case because the indexing to original is inconsistent within the for loops, as in you cannot do this:
parfor j = 1:3
for k = 1:3
A(j, k) = -1; %MATLAB: got it, will refer to A via A(j, k) indexing
A(j, 3-k+1) = -2; %ERROR! A must be referred to via same index schemes
%Must use A(j, k) all the way through inside parfor
end
end
Also, do not override matlab built-in functions such as flip and size, as this will cause issues. To learn more about these, type this in your command window:
>> help size
>> help flip
To prevent overriding MATLAB functions accidentally, use variable names starting with Capital letters EX:
for Size = 1:half %OK! Size will not override size.m
...
end
0 commentaires
Voir également
Catégories
En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!