function submat = selectResults(cv,fieldsstruct)
% submat = selectResults(CV.msf,struct('TestTrial',1,'nlags',3,'winSize',125))

%%% combine cv results into their mean
nreps = cv.validate.repetitions;
mat = cv.cvresults(:,1:end-nreps);
z=cv.cvresults(:,end-nreps+1:end);
mat = [mat mean(cv.cvresults(:,end-nreps+1:end),2)];

rows = ones(size(mat,1),1);

[values,fields] = getfields(fieldsstruct);

for f = 1:length(fields)
  field = fields{f};
  col = find(strcmp(cv.cvresultsNames,field));
  rows = rows & (mat(:,col)==values(f));
end

submat = mat(rows,:);
