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

Mech Saints
Mech Saints 2020년 10월 11일
can you provide code. I tried but i dont know why the results i get are not satisfactory
Walter Roberson
Walter Roberson 2020년 10월 11일
편집: Walter Roberson 2020년 10월 11일
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.
Mech Saints
Mech Saints 2020년 10월 11일
Got it. I wasn't checking for char

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Data Type Identification에 대해 자세히 알아보기

제품

릴리스

R2020b

질문:

2020년 10월 9일

댓글:

2020년 10월 11일

Community Treasure Hunt

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

Start Hunting!

Translated by