name value pairs assignment help

i have to write a function having variable number of input arguments. They should come in pairs (e.g name and its value). The function should return single array and if no arguments or with odd inputs or if name is not char type, It returns an empty cell.
PS: for name value pairs here, it consists of a name(char type) and a value that can be of any data type.

回答(1 个)

Walter Roberson
Walter Roberson 2020-10-9

0 个投票

you can test nargin for being odd. You can use varargin and cellfun @ischar every second entry of varargin

3 个评论

can you provide code. I tried but i dont know why the results i get are not satisfactory
Have you been successful in writing code to test whether a number is odd?
Have you been successful in writing a simple function that takes at least one argument?
Have you been successful in selecting every second entry in an array?
Note: varargin can only be used inside a function, not in a script.
Got it. I wasn't checking for char

请先登录,再进行评论。

类别

帮助中心File Exchange 中查找有关 Data Type Identification 的更多信息

产品

版本

R2020b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by