%% New in r2021a: Name=Value syntax
% Author: Adam Danz
% March  31, 2021
% https://www.mathworks.com/matlabcentral/highlights
%
% Starting in Matlab r2021a, name-value arguments have a new optional syntax!
% A property name can be paired with its value by an equal sign and the property name is not enclosed in quotes.
% Compare the comma-separated name,value syntax to the new equal-sign syntax, either of which can be used in >=r2021a:
% plot(x, y, "b-", "LineWidth", 2)
% plot(x, y, "b-", LineWidth=2)
% It comes with some rules & limitations:
% It's recommended to use only one syntax in a function call but if you're feeling rebellious and want to mix the syntaxes, all of the name=value arguments must appear after the comma-separated name,value arguments.
% Like the comma-separated name,value arguments, the name=value arguments must appear after positional arguments.
% Name=value pairs must be used directly in function calls and cannot be wrapped in cell arrays or additional parentheses.
% The property names are not case-sensitive so color='r' and Color='r' are both supported.
% The new syntax is helpful in distinguishing property names from property values in long lists of name-value arguments within the same line.
% For example,
% h = uicontrol(hfig, "Style", "checkbox", "String", "Long", "Units", "Normalize", "Tag", "chkBox1", "Enable", "inactive")
% can be written as
% h = uicontrol(hfig, Style="checkbox", String="Long", Units="Normalize", Tag="chkBox1", Enable="inactive")
%
% Here's another side-by-side comparison.  See the attached mlx file for all content of this Community Highlight.
%

r=5;
[a, b] = meshgrid(pi:20/180*pi:2*pi);
X=((r+10)+r*cos(a)).*cos(b);
Y=((r+10)+r*cos(a)).*sin(b);
Z=r.*sin(a);

fig = figure();
ax = axes(fig);
hsurf = surf(ax,X,Y,Z, ...
    LineStyle='-', ...
    EdgeColor=ax.GridColor, ...
    EdgeAlpha=.8,...
    MeshStyle='row', ...
    FaceColor='interp', ...
    FaceAlpha=4/5, ...
    FaceLighting='gouraud',...
    BackFaceLighting='lit', ...
    AmbientStrength=0.3, ...
    DiffuseStrength=0.9,...
    SpecularStrength=0.2, ...
    SpecularExponent=3);

light()

set(ax, DataAspectRatio=[1 1 1], ...
    Colormap=flipud(turbo(255)),...
    color=.86*ones(1,3), ...
    GridAlpha=.25, ...
    view=[-135 20]); 

title(ax,'Internal toroidal surface', ...
    FontName='FixedWidth',...
    FontSize=12, ...
    FontWeight='bold', ...
    rotation=-19, ...
    Units='data',...
    Position=[0 -20 0])

% Comma=separated version

hsurf = surf(ax,X,Y,Z, ...
    'LineStyle','-', ...
    'EdgeColor',ax.GridColor, ...
    'EdgeAlpha',.8,...
    'MeshStyle','row', ...
    'FaceColor','interp', ...
    'FaceAlpha',4/5, ...
    'FaceLighting','gouraud',...
    'BackFaceLighting','lit', ...
    'AmbientStrength',0.3, ...
    'DiffuseStrength',0.9,...
    'SpecularStrength',0.2, ...
    'SpecularExponent',3);

light()

set(ax,'DataAspectRatio',[1 1 1], ...
    'Colormap',flipud(turbo(255)),...
    'color',.86*ones(1,3), ...
    'GridAlpha',.25, ...
    'view',[-135 20]); 

title(ax,'Internal toroidal surface', ...
    'FontName','FixedWidth',...
    'FontSize',12, ...
    'FontWeight','bold', ...
    'rotation',-19, ...
    'Units','data',...
    'Position',[0 -20 0])