function A = nv2struct(names,values)
% This ia utility to take the 2 cell-arrays of
% of the Names/Values format (each cell array
% is a column vector), and pack everything correctly
% into a structure.

% Copyright 2003-2004 The MathWorks, Inc.

if isa(names,'cell') && isa(values,'cell') && ...
      ndims(names)==2 && ndims(values)==2 && ...
      size(names,2)==1 && size(values,2)==1 && ...
      size(names,1)==size(values,1)
   n = length(names);
   cvalues = cell(n,1);
   for i=1:n
      szv = size(values{i});
      cvalues{i} = cell([szv(3:end) 1 1]);
      for k=1:prod(szv(3:end))
         cvalues{i}{k} = values{i}(:,:,k);
      end
   end
   PNVcell = [names cvalues]';
   A = struct(PNVcell{:});
else
   error('Names and Values should be cell arrays of same length.');
end
