namedargs2cell
Convert structure containing name-value pairs to cell array
Syntax
Description
Examples
Convert Structure to Interleaved Cell Array
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.
S.XLim = [1,100]; S.Color = "red"; S.Box = "on"; C = namedargs2cell(S)
C = 1×6 cell array {'XLim'} {1×2 double} {'Color'} {["red"]} {'Box'} {["on"]}
Convert Name-Value Structure for Name-Value Pairs
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.OnOffSwitchState end 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");
Input Arguments
S
— Name-value structure
structure
Name-value structure, specified as a scalar structure array.
Data Types: struct
Output Arguments
C
— Cell array of interleaved names and values
cell array
Cell array of interleaved names and values, returned as a 1-by-2n cell array, where n is the number of fields in the input structure.
Data Types: cell
Extended Capabilities
C/C++ Code Generation
Generate C and C++ code using MATLAB® Coder™.
Thread-Based Environment
Run code in the background using MATLAB® backgroundPool
or accelerate code with Parallel Computing Toolbox™ ThreadPool
.
This function fully supports thread-based environments. For more information, see Run MATLAB Functions in Thread-Based Environment.
Version History
Introduced in R2019b
Comando MATLAB
Hai fatto clic su un collegamento che corrisponde a questo comando MATLAB:
Esegui il comando inserendolo nella finestra di comando MATLAB. I browser web non supportano i comandi MATLAB.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
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.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)