C = namedargs2cell(S) converts a scalar structure array containing name-value pairs to a cell array containing the names and values. This function converts a 1-by-1 structure with n number of fields to a 1-by-2n cell array with interleaved names and values.
Create a structure with the fields XLim, Color, and Box and assign values to each field. Use namedargs2cell to convert the structure to a cell array that interleaves the field names and the values.
Write a function that accepts name-value pairs for specific axes object properties and impose additional restrictions on those property values.
Convert a name-value structure to a cell array containing interleaved names and values. Pass the cell array to the axes function, which accepts name-value pairs in a cell array. Return the handle to the axes object.
function a = myAxes(axesProps)
arguments
axesProps.XLim (1,2) {mustBeNumeric}
axesProps.Color string {mustBeMember(axesProps.Color,["red","green","blue"])}
axesProps.Box matlab.lang.OnOffSwitchStateend
nvCell = namedargs2cell(axesProps);
a = axes(nvCell{:});
end
The output of the namedarg2cell function converts the axesProps name-value structure defined in the arguments block to an interleaved cell array of names and values. Pass the nvCell cell array to the axes function, which accepts name-value pairs as a cell array.
a = myAxes("XLim",[1,10],"Color","red","Box","on");
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.