This section of code is meant to take an even number of input arguments and return them as a cell array with two columns, one for the name and one for the value. With the test input I've been given it is only returning the the third and forth input arguments as a 1×1 cell array where as I'm looking for a 2×2 cell array. Is the issue with the ii indexing? Can I not do it like I've written here?
db = name_value_pairs('name','John Smith','age',32)
function [db]=name_value_pairs(varargin) for ii = 1:2:(length(varargin)-1) for i = 1:(length(varargin)/2) x(i,1) = varargin(ii); end end for ii = 2:2:length(varargin) for i = 1:(length(varargin)/2) x(i,2) = varargin(ii); end end db = {x};end
db = 1×1 cell array {2×2 cell}
Thank you for any help or advice!
Best Answer