Index exceeds the number of array elements (27).
Error in (line 307)
newFN_prime2(i,:) = FN_BNScombined2(i,:) + flow_node_array(GroupList2(i),:);
BioM_3D_250076_1 = importdata('BioM_3D_250076_gen1.txt');
x = BioM_3D_250076_1.data(:, 1);
y = BioM_3D_250076_1.data(:, 2);
z = BioM_3D_250076_1.data(:, 3);
[x_dom,y_dom,z_dom] = sphere(80);
x_dom = x_dom(41:end,:);
y_dom = y_dom(41:end,:);
z_dom = z_dom(41:end,:);
hemisphere_radius = 80;
figure();
Hemi_sf = surf(hemisphere_radius.*x_dom,hemisphere_radius.*y_dom,hemisphere_radius.*z_dom, 'FaceColor','#4DBEEE','EdgeColor', 'none');
alpha 0.2
axis equal
x_ax_lab = xlabel('x axis', 'Color', '#4DBEEE');
y_ax_lab = ylabel('y axis', 'Color', '#4DBEEE');
z_ax_lab = zlabel('z axis', 'Color', '#4DBEEE');
x_c = 0;
y_c = 0;
z_c = 0;
radii_plane = 80;
center_plane = [x_c, y_c];
viscircles(center_plane, radii_plane, 'color', '#77AC30');
hold on
Center_Root = scatter3(x_c, y_c, z_c, 'filled', 'k');
n = 2500;
A = zeros(n,3);
A = [x, y, z];
BNS_gen1 = A;
BioM_3Dgraph1 = scatter3(x, y, z, 'filled', 'r');
elim_dist1a = nan(numel(x));
BNS_BNS_proximity = 1.5;
for i = 1:n
for j = 1:(i-1)
elim_dist1a(i,j) = sqrt((x(i)-x(j)).^2 + (y(i)-y(j)).^2 + (z(i)-z(j)).^2);
elim_dist1a(j,i) = elim_dist1a(i,j);
end
end
i2keepBNS_BNS = min(elim_dist1a) > BNS_BNS_proximity;
keep_x1 = x(i2keepBNS_BNS);
keep_y1 = y(i2keepBNS_BNS);
keep_z1 = z(i2keepBNS_BNS);
x_close_neighbors1 = x(~i2keepBNS_BNS);
y_close_neighbors1 = y(~i2keepBNS_BNS);
z_close_neighbors1 = z(~i2keepBNS_BNS);
B = [keep_x1, keep_y1, keep_z1];
SizeofB = size(B,1);
proximity_matrix = triu(elim_dist1a);
proximity_matrix(proximity_matrix == 0) = nan;
[proximity_rowx, proximity_coly] = find(proximity_matrix < BNS_BNS_proximity);
BNS2replace1 = [proximity_rowx, proximity_coly];
if BNS2replace1 ~= 0
BNS2replace_indx = BNS2replace1;
BNS_distinct = unique(BNS2replace_indx(:));
BNS2replace_indx(ismember(BNS2replace_indx,BNS_distinct(histc(BNS2replace_indx(:),BNS_distinct)>1))) = Inf;
BNS2return_index = min(BNS2replace_indx,[], 2);
BNS2return_index = BNS2return_index(isfinite(BNS2return_index));
sizeBNS2return_index = size(BNS2return_index, 1);
for k = 1:sizeBNS2return_index
BNS2return1(k,:) = A(BNS2return_index(k),:);
end
end
if BNS2replace1 ~= 0
B = [B;BNS2return1];
keep_x1 = B(:,1);
keep_y1 = B(:,2);
keep_z1 = B(:,3);
end
delete(BioM_3Dgraph1);
BioM_3Dgraph1 = scatter3(keep_x1, keep_y1, keep_z1, 'filled', 'r');
SizeofB = size(B,1);
flow_node_array = [x_c, y_c, z_c];
FNA_x = flow_node_array(:,1);
FNA_y = flow_node_array(:,2);
FNA_z = flow_node_array(:,3);
SizeofFNA = size(flow_node_array,1);
elim_dist2a = nan(numel(keep_x1));
FN_BNS_threshold = 2;
for i = 1:SizeofB
for j = 1:SizeofFNA
elim_dist2a(j,i) = sqrt((keep_x1(i)-FNA_x(j)).^2 + (keep_y1(i)-FNA_y(j)).^2 +(keep_z1(i)-FNA_z(j)).^2);
end
end
i2keepFN_BNS1 = min(elim_dist2a)> FN_BNS_threshold;
keep_x2 = keep_x1(i2keepFN_BNS1);
keep_y2 = keep_y1(i2keepFN_BNS1);
keep_z2 = keep_z1(i2keepFN_BNS1);
x_close_neighbors2 = keep_x1(~i2keepFN_BNS1);
y_close_neighbors2 = keep_y1(~i2keepFN_BNS1);
z_close_neighbors2 = keep_z1(~i2keepFN_BNS1);
C = [keep_x2, keep_y2, keep_z2];
BNS_kept = C;
delete(BioM_3Dgraph1);
BioM_3Dgraph1 = scatter3(keep_x2, keep_y2, keep_z2, 'filled', 'r');
distFNA_BNS1 = pdist2(flow_node_array, BNS_kept);
[~, minRowIdx] = min(distFNA_BNS1,[],1);
[GroupID, GroupList1] = findgroups(minRowIdx);
FN_BNSNeighborGroups1 = splitapply(@(x){x},BNS_kept,GroupID(:));
SizeFN_BNSG1 = size(FN_BNSNeighborGroups1,1);
for i = 1:SizeFN_BNSG1
FN_BNSvectors1{i,:} = FN_BNSNeighborGroups1{i}-flow_node_array(GroupList1(i),:);
FN_BNSaddition1(i,:) = sum(FN_BNSvectors1{i},1);
end
FN_BNScombined1 = 1*(FN_BNSaddition1./vecnorm(FN_BNSaddition1,2,2));
SizeFN_BNS_Comb1 = size(FN_BNScombined1, 1);
for i = 1:SizeFN_BNS_Comb1
newFN_prime1(i,:) = FN_BNScombined1(i,:) + flow_node_array(GroupList1(i),:);
end
if any(ismember(newFN_prime1,flow_node_array))
FN_FN_threshold = 0.25;
SizeNewFN_prime = size(newFN_prime1, 1);
newFN_primex = newFN_prime1(:,1);
newFN_primey = newFN_prime1(:,2);
newFN_primez = newFN_prime1(:,3);
reconfig_dist = nan(numel(FNA_x));
for j = 1:SizeofFNA
for i = 1:SizeNewFN_prime
reconfig_dist(j,i) = sqrt((newFN_primex(i)-FNA_x(j)).^2 + (newFN_primey(i)-FNA_y(j)).^2 + (newFN_primez(i)-FNA_z(j)).^2);
end
end
i2keepFN_FN = find(min(reconfig_dist)> FN_FN_threshold);
inot2keepFN_FN = find(min(reconfig_dist)< FN_FN_threshold);
x_newFN_retained = newFN_primex(i2keepFN_FN);
y_newFN_retained = newFN_primey(i2keepFN_FN);
z_newFN_retained = newFN_primez(i2keepFN_FN);
x_notkept = newFN_primex(~i2keepFN_FN);
y_notkept = newFN_primey(~i2keepFN_FN);
z_notkept = newFN_primez(i2keepFN_FN);
newFN_retained = [x_newFN_retained, y_newFN_retained, z_newFN_retained];
FN_VectorGroupNum = inot2keepFN_FN;
FN_reconfig = FN_BNSvectors1{FN_VectorGroupNum};
FN_BNScombBeta = 1*(FN_reconfig./vecnorm(FN_reconfig,2,2));
SizeFN_BNScombBeta = size(FN_BNScombBeta,1);
FNconfig_beta = FN_BNScombBeta(:,:) + flow_node_array(GroupList1(FN_VectorGroupNum),:);
newFN_prime1 = [newFN_retained;FNconfig_beta];
SizeFN_BNS_Comb1 = size(newFN_prime1,1);
end
scatter3(newFN_prime1(:, 1), newFN_prime1(:, 2), newFN_prime1(:, 3), 'filled', 'k');
flow_node_array = [flow_node_array; newFN_prime1;];
FNA_x = flow_node_array(:, 1);
FNA_y = flow_node_array(:, 2);
FNA_z = flow_node_array(:, 3);
SizeofFNA = size(flow_node_array,1);
newFN_prime_x = newFN_prime1(:, 1);
newFN_prime_y = newFN_prime1(:, 2);
newFN_prime_z = newFN_prime1(:, 3);
SizeNewFN_prime = size(newFN_prime1,1);
SizeofC = size(C,1);
elim_dist3a = nan(numel(keep_x2));
FN_BNS_threshold = 2;
for i = 1:SizeofC
for j = 1:SizeNewFN_prime
elim_dist3a(j,i) = sqrt((keep_x2(i)-newFN_prime_x(j)).^2 + (keep_y2(i)-newFN_prime_y(j)).^2 + (keep_z2(i)-newFN_prime_z(j)).^2);
end
end
i2keepFN_BNS2 = min(elim_dist3a)> FN_BNS_threshold;
keep_x3 = keep_x2(i2keepFN_BNS2);
keep_y3 = keep_y2(i2keepFN_BNS2);
keep_z3 = keep_z2(i2keepFN_BNS2);
x_close_neighbors3 = keep_x2(~i2keepFN_BNS2);
y_close_neighbors3 = keep_y2(~i2keepFN_BNS2);
z_close_neighbors3 = keep_z2(~i2keepFN_BNS2);
D = [keep_x3, keep_y3, keep_z3];
BNS_kept = D;
BNSx_absorbed = x_close_neighbors3;
BNSy_absorbed = y_close_neighbors3;
BNSz_absorbed = z_close_neighbors3;
BNS_absorbed = [BNSx_absorbed, BNSy_absorbed];
BNSabs_graph = scatter3(BNSx_absorbed, BNSy_absorbed, BNSz_absorbed, 'kX');
SizeBNS_keptCount = size(BNS_kept,1);
itr = 0;
while SizeBNS_keptCount >= 0
distFNA_BNS2 = pdist2(flow_node_array, BNS_kept);
[~, minRowIdx] = min(distFNA_BNS2,[],1);
[GroupID, GroupList2] = findgroups(minRowIdx);
FN_BNSNeighborGroups2 = splitapply(@(x){x},BNS_kept,GroupID(:));
SizeFN_BNSG2 = size(FN_BNSNeighborGroups2,1);
for i = 1:SizeFN_BNSG2
FN_BNSvectors2{i,:} = FN_BNSNeighborGroups2{i}-flow_node_array(GroupList2(i),:);
FN_BNSaddition2(i,:) = sum(FN_BNSvectors2{i},1);
end
FN_BNScombined2 = 1*(FN_BNSaddition2./vecnorm(FN_BNSaddition2,2,2));
SizeFN_BNS_Comb2 = size(FN_BNScombined2, 1);
for i = 1:SizeFN_BNS_Comb2
newFN_prime2(i,:) = FN_BNScombined2(i,:) + flow_node_array(GroupList2(i),:);
end
if any(ismember(newFN_prime2,flow_node_array))
FN_FN_threshold = 0.25;
SizeNewFN_prime = size(newFN_prime2, 1);
newFN_primex = newFN_prime2(:,1);
newFN_primey = newFN_prime2(:,2);
newFN_primez = newFN_prime2(:,3);
reconfig_dist = nan(numel(FNA_x));
for j = 1:SizeofFNA
for i = 1:SizeNewFN_prime
reconfig_dist(j,i) = sqrt((newFN_primex(i)-FNA_x(j)).^2 + (newFN_primey(i)-FNA_y(j)).^2 + (newFN_primez(i)-FNA_z(j)).^2);
end
end
i2keepFN_FN = find(min(reconfig_dist)> FN_FN_threshold);
inot2keepFN_FN = find(min(reconfig_dist)< FN_FN_threshold);
x_newFN_retained = newFN_primex(i2keepFN_FN);
y_newFN_retained = newFN_primey(i2keepFN_FN);
z_newFN_retained = newFN_primez(i2keepFN_FN);
x_notkept = newFN_primex(~i2keepFN_FN);
y_notkept = newFN_primey(~i2keepFN_FN);
z_notkept = newFN_primez(i2keepFN_FN);
newFN_retained = [x_newFN_retained, y_newFN_retained, z_newFN_retained];
FN_VectorGroupNum = inot2keepFN_FN;
FN_reconfig = FN_BNSvectors2{FN_VectorGroupNum};
FN_BNScombBeta = 1*(FN_reconfig./vecnorm(FN_reconfig,2,2));
SizeFN_BNScombBeta = size(FN_BNScombBeta,1);
FNconfig_beta = FN_BNScombBeta(:,:) + flow_node_array(GroupList2(FN_VectorGroupNum),:);
newFN_prime2 = [newFN_retained;FNconfig_beta];
SizeFN_BNS_Comb2 = size(newFN_prime2,1);
end
scatter3(newFN_prime2(:, 1), newFN_prime2(:, 2), newFN_prime2(:, 3), 'filled', 'k');
flow_node_array = [flow_node_array; newFN_prime2];
FNA_x = flow_node_array(:, 1);
FNA_y = flow_node_array(:, 2);
FNA_z = flow_node_array(:, 3);
newFN_prime_x = newFN_prime2(:, 1);
newFN_prime_y = newFN_prime2(:, 2);
newFN_prime_z = newFN_prime2(:, 3);
SizeNewFN_prime = size(newFN_prime2,1);
SizeofBNS_kept = size(BNS_kept,1);
BNS_keptx = BNS_kept(:,1);
BNS_kepty = BNS_kept(:,2);
BNS_keptz = BNS_kept(:,3);
elim_dist4 = nan(numel(BNS_keptx));
FN_BNS_threshold = 2;
for i = 1:SizeofBNS_kept
for j = 1:SizeNewFN_prime
elim_dist4(j,i) = sqrt((BNS_keptx(i)-newFN_prime_x(j)).^2 + (BNS_kepty(i)-newFN_prime_y(j)).^2 + (BNS_keptz(i)-newFN_prime_z(j)).^2);
end
end
i2keepFN_BNS2 = min(elim_dist4)> FN_BNS_threshold;
keep_x4 = BNS_keptx(i2keepFN_BNS2);
keep_y4 = BNS_kepty(i2keepFN_BNS2);
keep_z4 = BNS_keptz(i2keepFN_BNS2);
x_close_neighbors4 = BNS_keptx(~i2keepFN_BNS2);
y_close_neighbors4 = BNS_kepty(~i2keepFN_BNS2);
z_close_neighbors4 = BNS_keptz(~i2keepFN_BNS2);
E = [keep_x4, keep_y4, keep_z4];
BNS_kept = E;
SizeBNS_keptCount = size(BNS_kept,1);
SizeNewFN_prime = 0;
SizeFN_BNS_Comb2 = 0;
SizeFN_BNSG2 = 0;
BNSx_absorbed = x_close_neighbors4;
BNSy_absorbed = y_close_neighbors4;
BNSz_absorbed = z_close_neighbors4;
BNS_absorbed = [BNSx_absorbed, BNSy_absorbed, BNSz_absorbed];
BNSabs_graph = scatter3(BNSx_absorbed, BNSy_absorbed, BNSz_absorbed, 'kX');
itr = itr+1;
end