Error using histogram in parlor-loop

1 visualización (últimos 30 días)
Jens Lindahl
Jens Lindahl el 30 de Abr. de 2019
Comentada: Edric Ellis el 12 de Sept. de 2019
Hey,
I have trouble using histogram in a parfor-loop. Below is a minimal-working-example of my problem:
parfor idx = 1:2
x = randn(1,50*idx);
f = figure()
histogram(x,'Normalization','pdf')
drawnow
end
This gives me the response:
Error using histogram (line 140)
Transparency violation error.
See Parallel Computing Toolbox documentation about Transparency
Error in untitled6 (line 3)
parfor idx = 1:2
I get the error with both R2018a and R2018b
Best regards,
  1 comentario
Edric Ellis
Edric Ellis el 12 de Sept. de 2019
Note this is fixed in R2019b, out now!

Iniciar sesión para comentar.

Respuesta aceptada

Edric Ellis
Edric Ellis el 1 de Mayo de 2019
Unfortunately, histogram tries to extract the name of the input variable, and this causes the transparency violation. You can work around this problem by hiding the call to histogram inside an anonymous function, like this:
histFcn = @(x) histogram(x, 'Normalization', 'pdf');
parfor idx = 1:2
x = rand(1, 50*idx);
histFcn(x);
end
  1 comentario
Jens Lindahl
Jens Lindahl el 1 de Mayo de 2019
I figured might be caused by some eval-like function.
For whom it may concern, it also works if you to include multiple variable inputs to the histogram function, as an example;
histFcn = @(x,c) histogram(x, 'Normalization', 'pdf', 'FaceColor', c);
Thanks Edric!

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Histograms en Help Center y File Exchange.

Productos


Versión

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by