saveCenters.m 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. function saveCenters(path, patientID, cax, cm, data, nclass, nRealizations)
  2. %path is the core directory
  3. %cax are the mid intervals in images
  4. %cm are the interval durations (1,n)
  5. %data are the images
  6. %nclass is number of typical responses sought
  7. %nRealizations is number of realizations
  8. c1=size(cax,1);
  9. A=reshape(data,[],c1);
  10. if nclass==10
  11. fuzzyPar=1.5;
  12. end
  13. if nclass==20
  14. fuzzyPar=1.45;
  15. end
  16. if nclass==30
  17. fuzzyPar=1.4;
  18. end
  19. options=[fuzzyPar 100 1 true];
  20. dt=size(data);
  21. for j=1:nRealizations
  22. [centers,U]=fcm(A,nclass,options);
  23. for i=1:nclass
  24. code=sprintf('%s_%d_%d_center%d',patientID,nclass,j,i);
  25. ofile=fullfile(path,patientID,sprintf('%s_center.txt',code));
  26. try
  27. writematrix(centers(i,:),ofile,'Delimiter',',');
  28. catch ME
  29. dlmwrite(ofile,centers(i,:),',');
  30. end
  31. u=reshape(U(i,:),dt(1:3));
  32. headerInfoOut.data=single(u);
  33. headerInfoOut.content=sprintf('%s_centerWeight',code);
  34. nhdr_nrrd_write(fullfile(path,patientID, sprintf('%s_centerWeight.nrrd',code)),headerInfoOut,1);
  35. end
  36. end