0001 function [clsts,clsts_size,n_clsts] = nsw_clusterSW_clstrs(nodes_rwd,d0,n,nodes_rwd_list)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022 if(isempty(nodes_rwd) && nargin ==4)
0023 pos = nodes_rwd_list;
0024 else
0025 pos = find(nodes_rwd>0);
0026 end
0027 if(isempty(pos))
0028 return;
0029 end
0030 clsts={};clsts_size =[];
0031 k=1;cls_k=[];last = 0;
0032 while(~isempty(pos))
0033 if(last ==0 || pos(1)==last+1)
0034 last = pos(1);
0035 cls_k = [cls_k last];
0036 else
0037 clsts{k,1}=cls_k;
0038 clsts_size = [clsts_size; length(cls_k)];
0039 last = pos(1);
0040 k=k+1; cls_k =[last];
0041 end
0042 pos = pos(2:length(pos));
0043 end
0044 clsts{k,1}=cls_k;clsts_size = [clsts_size; length(cls_k)];
0045
0046
0047
0048
0049
0050
0051
0052
0053
0054
0055 n_clsts = k;
0056
0057
0058 plot_result = 0;
0059 if(plot_result)
0060 disp([num2str(n_clsts),' clusters are shown below:']);
0061 meansize_txt = ['mean of cluster size =',num2str(mean(clsts_size))];
0062 disp(meansize_txt);
0063 for k=1:n_clsts
0064 str1 = sprintf('%3.0f-cluster (%3.0f node(s)):',k , clsts_size(k));
0065 form2 = [];
0066 for m = 1:clsts_size(k)
0067 form2 = [form2,'%7.0f '];
0068 end
0069 str2 = sprintf(form2,clsts{k}');
0070
0071 disp([str1, str2]);
0072 end
0073 figure; hist(clsts_size,1:max(clsts_size)+1);
0074 xlabel('cluster size'); ylabel('n_c_l');
0075 title(meansize_txt);
0076 end