Skip to content

Instantly share code, notes, and snippets.

@yuchung-chuang
Created August 6, 2017 21:01
Show Gist options
  • Save yuchung-chuang/e0e508ecd8d702ce03a5589fe614dc68 to your computer and use it in GitHub Desktop.
Save yuchung-chuang/e0e508ecd8d702ce03a5589fe614dc68 to your computer and use it in GitHub Desktop.
function obj = varassign( obj, var )
if nargin < 2 || isempty(var)
return
end
nvarin = numel(var);
assert( ~mod( nvarin, 2 ), 'Field and value input arguments must come in pairs.' );
for i = 1:2:nvarin-1
mc = metaclass(obj);
[~, LocB] = ismember(lower(var{i}),lower({mc.PropertyList.Name}));
obj.(mc.PropertyList(LocB).Name) = var{i+1};
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment