MATLAB: How to get the ‘light’ in a 3d plot to appear in the generated code for a figure

MATLAB

I have a 3d plot and am using the 'Orbit Scene Camera Light' or the 'Toggle Scene Camera Light' options to change the position of the lighting on the image.
I want to save the final position of the light, so I select File > Generate Code. Usually, this shows me all the code necessary to regenerate the plot exactly as it sits. However, the light does not appear in the code, nor does it appear in the new plot that is created from executing the generated code.
Why is this the case?

Best Answer

Simply using the Camera Toolbar options for changing the lighting does not create a 'Light' object. In order to get the lighting to appear in the generated code for the figure, please first select 'Insert' and then select 'Light' from the drop-down menu.
'Orbit Scene Camera Light' can then be used to change the position of the light in addition to the property inspector which should appear to the right of the figure window. When you generate code, the lighting object will be present.