0001 function ss = get_stable_sets(cdata, scs)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014 nsess = length(scs);
0015
0016 stable_ics = find(scs{1});
0017 nstable = length(stable_ics);
0018
0019 ss = {};
0020 for istable = 1:nstable
0021 start_ic_idx = stable_ics(istable);
0022 fprintf('Conjoining ICs starting with session 1 IC %d\n', start_ic_idx);
0023
0024 curr_ic_idx = start_ic_idx;
0025
0026 curr_chain_idx = 1;
0027 ss{istable} = [];
0028 ss{istable}(1,:) = [1 curr_ic_idx];
0029 for isess = 1:nsess
0030 jsess = mod(isess,nsess)+1;
0031 tmp = cdata{isess,jsess}(curr_ic_idx,:)' .* repmat(scs{jsess},1,length(curr_ic_idx));
0032 curr_ic_idx = find(any(tmp,2));
0033 nic = length(curr_ic_idx);
0034 if nic
0035 start_idx = size(ss{istable},1)+1;
0036 stop_idx = start_idx+nic-1;
0037 ss{istable}(start_idx:stop_idx,:) = [ones(nic,1)*jsess,curr_ic_idx(:)];
0038 else
0039 break
0040 end
0041 end
0042
0043
0044 ss{istable} = unique(ss{istable},'rows');
0045
0046 end