I am trying to solve this question using "name_value_pairs" but it is accepting "wrong type for name", rest the code is running just fine ...
Can you please guide me what am i doing wrong!
The code i am using is given below!
function db = name_value_pairs(varargin)
d=0;
if (nargin == 0 || rem(length(varargin),2)~=0)
d = cell (0,0);
else
for i = 1:2:length(varargin)-1
if ~ischar(varargin{i})
d= cel(0,0);
break
end
end
end
if isequal(d,cell(0,0))
db = cell(0,0);
else
db = reshape(varargin,2,length(varargin)/2)' ;
end
end

4 件のコメント

Adam Danz
Adam Danz 2020 年 10 月 17 日
Make it easier for us to help you by
  • providing some inputs that recreate the error
or
  • sharing the entire error message
  • tell us what line is causing the error
Ahsan Rasheed
Ahsan Rasheed 2020 年 10 月 17 日
編集済み: Ahsan Rasheed 2020 年 10 月 17 日
There is no error in code.
The only problem is that it is not checking if someone enter wrong type of data for name input.
Adam Danz
Adam Danz 2020 年 10 月 17 日
What is " name input"?
What type of data do you expect?
Is your question, "how do I validate the input values"?
Typo here
d= cel(0,0);
% ^^^ should be "cell"
Ahsan Rasheed
Ahsan Rasheed 2020 年 10 月 17 日
That typo solved the problem!
Thank you so much for the help :)

サインインしてコメントする。

 採用された回答

Matt J
Matt J 2020 年 10 月 17 日
編集済み: Matt J 2020 年 10 月 17 日

0 投票

1 件のコメント

Ahsan Rasheed
Ahsan Rasheed 2020 年 10 月 17 日
Thank you Matt :)

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File Exchange で Argument Definitions についてさらに検索

製品

質問済み:

2020 年 10 月 17 日

コメント済み:

2020 年 10 月 17 日

Community Treasure Hunt

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

Start Hunting!

Translated by