The Zmatrix only contains the 3D data to represent the surface, it is not affected by the lighting / shading setting you are applying later-on to its visualization.
If you want to reproduce the figure you've obtained by loading "some saved data", you have to save the Z matrix (it should be better to save also X and Y) along the values of the lighting setting.
To do this you first have to modify your code by assigning the lightig values to a corresponding set of variables, then you have to use this vatiables to set the lighting.
At the end you have to save all these variables.
[X,Y] = meshgrid(-2:.025:2);
Z = peaks(X,Y);
h = surf(X,Y,Z);
% Necessary for task
%h.AmbientStrength = 0.;
%h.SpecularStrength = 0.;
%h.DiffuseStrength = 1.;
%h.BackFaceLighting = 'unlit';
%h.FaceLighting = 'gouraud';
% Assign the setting values to a set of varialbles
AmbientStrength_val=0.;
SpecularStrength_val=0.;
DiffuseStrength_val=1.;
BackFaceLighting_val='unlit';
FaceLighting_val='gouraud';
h.AmbientStrength = AmbientStrength_val;
h.SpecularStrength = SpecularStrength_val;
h.DiffuseStrength = DiffuseStrength_val;
h.BackFaceLighting = BackFaceLighting_val;
h.FaceLighting = FaceLighting_val;
view_val=2;
%view(2);
view(view_val);
light_pos=[-2, -2, 50]
light_style='local'
light_color=[1 1 1]
%l = light('Position',[-2, -2, 50],'Style','local','Color',[1 1 1]);
l = light('Position',light_pos,'Style',light_style,'Color',light_color);
save('data_peaks.mat','X','Y','Z','AmbientStrength_val','SpecularStrength_val', ...
'DiffuseStrength_val','BackFaceLighting_val', ...
'FaceLighting_val','light_pos','light_style', ...
'light_color','view_val')
To reproduce the figure, in the future, you can have a script like the following:
% Load the saved values
load data_peaks
% Plot the surface
h = surf(X,Y,Z);
% Set the parameters
h.AmbientStrength = AmbientStrength_val;
h.SpecularStrength = SpecularStrength_val;
h.DiffuseStrength = DiffuseStrength_val;
h.BackFaceLighting = BackFaceLighting_val;
h.FaceLighting = FaceLighting_val;
view(view_val);
l = light('Position',light_pos,'Style',light_style,'Color',light_color);
h.LineStyle='none';? - Ander Biguri