parfor shows an empty figure

Hello,
I am trying to use parfor to plot some filled rectangles with the following codes for some data x,y,f and a parameter l, this code works fine on serial for loop, when I tried to do it with parfor, it returns an empty figure, how should I resolve this? Thank you!
figure();
for i = 1:length(f)
if f(i)==1
fill( [x(i) x(i)+l x(i)+l x(i)],...
[y(i) y(i) y(i)+l y(i)+l],[0 91 187]/255,'LineStyle','none');hold on;
end
end

6 commentaires

Adam
Adam le 17 Déc 2019
I don't think plotting instructions are supported by parallel processing, though I may be wrong.
J T
J T le 17 Déc 2019
I have used similar codes previously to plot scattered data points, so I believe it does support, or at least in the lastest versions.
Adam Danz
Adam Danz le 17 Déc 2019
Could it be that l (bad variable name) is equal to 0? In that case, the patch produced by fill() would have an area of 0 (not visible).
J T
J T le 17 Déc 2019
Modifié(e) : J T le 17 Déc 2019
l is not zero, is a fixed positive length for all data points, note that the exact same code works in serial, it is just taking forever. Btw, why is l a bad variable name?
Adam Danz
Adam Danz le 17 Déc 2019
Modifié(e) : Adam Danz le 17 Déc 2019
" Btw, why is l a bad variable name"
  • l looks like 1. When a human is reading your code, it's very easy to misinterpret y(i)+l as adding 1
  • Single character variable names are often used in loops (for i = 1:10) and to represent common variables such as p-values (p = anova1(...)) but in general, it's best to use variable names with more than 1 character.
  • When using the editor, if you select a variable you'll notice that all instances of that variable within the same function are highlighted. With a variable name as narrow as l you lose the ability to quickly see all of those instances.
  • It's very easy to accidentally type a single-character variable name via a typo. It's much more difficult to accidentally type LValue than l.
J T
J T le 17 Déc 2019
Thanks! Good to learn!

Connectez-vous pour commenter.

Réponses (0)

Catégories

Produits

Version

R2019a

Question posée :

J T
le 17 Déc 2019

Commenté :

J T
le 17 Déc 2019

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by