Clear Filters
Clear Filters

'Exceeded the maximum number (8) of light sources' When trying to plot two shrinking spheres on the same figure

31 views (last 30 days)
I have written some code for a project which works out the radius of droplets of water as a function of time (r1,r2) depending on the input variables (size,temp,velocity) and I want to plot two droplets on the same figure shrinking to compare the two. The code works fine with one droplet but when I try to plot two spheres at the same time I get the warning Warning: 'Error updating Light Exceeded the maximum number (8) of light sources' and the figure stops updating. Here is the plotting part of the code:
for i = 1:size(r1,2)
[X,Y,Z] = sphere ;
if selection1(3)<5
surf(X*r1(i),Y*r1(i),Z*r1(i), 'FaceColor', [0 0 0.07*selection1(3)])
elseif selection1(3)<10
surf(X*r1(i),Y*r1(i),Z*r1(i), 'FaceColor', [0.15*selection1(3) 0.15*selection1(3) 0])
else
surf(X*r1(i),Y*r1(i),Z*r1(i), 'FaceColor', [0.07*selection1(3) 0 0])
end
hold on
if selection2(3)<5
surf(X*r2(i)+0.001,Y*r2(i),Z*r2(i), 'FaceColor', [0 0 0.07*selection2(3)])
elseif selection1(3)<10
surf(X*r2(i)+0.001,Y*r2(i),Z*r2(i), 'FaceColor', [0.15*selection2(3) 0.15*selection2(3) 0])
else
surf(X*r2(i)+0.001,Y*r2(i),Z*r2(i), 'FaceColor', [0.07*selection2(3) 0 0])
end
light('Position',[-1 -1 -1],'Style','local')
drawnow
axis([-0.0005 0.002 -0.001 0.001 -0.001 0.001])
pause(0.1)
end
The if else statements are just to set the colour of the sphere depending on the temperature.
Thank you

Answers (1)

xiaodong lu
xiaodong lu on 22 Mar 2024
You create too many figures and lights, try
>>gcf
and
>>delete(gcf)
then, you can use camlight() without warning again

Products


Release

R2018a

Community Treasure Hunt

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

Start Hunting!