% function [mystruct] = struct_from_array(thearray, thenames)
% return a struct given an array and fieldnames
% selects columns or rows based on #names: for square
% arrays defaults to using rows.
%
function [mystruct] = struct_from_array(thearray, thenames)
debug=1;
[nr,nc]=size(thearray); 
nflds=length(thenames);

for ii=1:nflds
    field_name = thenames{ii};
    values=[];
    if nr==nflds, 
      values=thearray(ii,:);
    else
        if nc==nflds
            values=thearray(:,ii);
        end
    end
    mycmd= ['mystruct.' field_name ' =  values;'];
    if debug ==1
      fprintf('%s \n',mycmd); 
    end
    eval(mycmd)
end
    
            

  

