nets_tsclean.m 1.0 KB

12345678910111213141516171819202122232425262728293031323334
  1. %
  2. % nets_tsclean - remove bad nodes, optionally regressing those out of the good (for further cleanup)
  3. % Steve Smith and Ludo Griffanti, 2013-2014
  4. %
  5. % [ts] = nets_tsclean(ts,aggressive);
  6. %
  7. % aggressive=0: "soft" - just deletes the bad and the unknown components
  8. % aggressive=1: regresses the bad timeseries (not in DD or UNK) out of the good, and deletes the bad & unknown components
  9. %
  10. % ts.DD = list of good components
  11. % ts.UNK = list of unknown components (gets deleted but never regressed out of good). Can be empty.
  12. %
  13. function [ts] = nets_tsclean(ts,aggressive);
  14. ts.NnodesOrig=ts.Nnodes;
  15. nongood=setdiff(1:ts.Nnodes,ts.DD); % bad or unknown components
  16. bad=setdiff(nongood,ts.UNK); % only bad components
  17. newts=[];
  18. for s=1:ts.Nsubjects
  19. grot=ts.ts((s-1)*ts.NtimepointsPerSubject+1:s*ts.NtimepointsPerSubject,:); % all comp
  20. goodTS=grot(:,ts.DD); %good comp
  21. badTS=grot(:,bad); % bad components
  22. if aggressive == 1
  23. newts=[newts;goodTS-badTS*(pinv(badTS)*goodTS)];
  24. else
  25. newts=[newts;goodTS];
  26. end
  27. end
  28. ts.ts=newts;
  29. ts.Nnodes=size(ts.ts,2);