Use a counter? Something like the following perhaps:
counter = 0;
for ii=1:length(Nodelocation(:,1))
for jj=1:length(UElocation(:,1))
if AssignCell(jj,2) == Nodelocation(ii,1)
if Nodelocation(ii,1) == 0 && ii == inputNodeID+1
a = scatter(Nodelocation(ii,2),Nodelocation(ii,3),150,[1 0 0],'^','filled');
hold on;
b = scatter(UElocation(jj,2),UElocation(jj,3),50,[0 0.5 0],'x');
counter = counter+1;
str(counter) = string(AssignCell(jj,1));
c = text(UElocation(jj,2),UElocation(jj,3),str);
end
if Nodelocation(ii,1) == 1 && ii == inputNodeID+1
a = scatter(Nodelocation(ii,2),Nodelocation(ii,3),150,[1 0 0],'^','filled');
hold on;
b = scatter(UElocation(jj,2),UElocation(jj,3),50,[0 0.5 0],'x');
counter = counter+1;
str(counter) = string(AssignCell(jj,1));
c = text(UElocation(jj,2),UElocation(jj,3),str);
end
end
end
end
or possibly:
str = [];
for ii=1:length(Nodelocation(:,1))
for jj=1:length(UElocation(:,1))
if AssignCell(jj,2) == Nodelocation(ii,1)
if Nodelocation(ii,1) == 0 && ii == inputNodeID+1
a = scatter(Nodelocation(ii,2),Nodelocation(ii,3),150,[1 0 0],'^','filled');
hold on;
b = scatter(UElocation(jj,2),UElocation(jj,3),50,[0 0.5 0],'x');
str = [str; string(AssignCell(jj,1))];
c = text(UElocation(jj,2),UElocation(jj,3),str);
end
if Nodelocation(ii,1) == 1 && ii == inputNodeID+1
a = scatter(Nodelocation(ii,2),Nodelocation(ii,3),150,[1 0 0],'^','filled');
hold on;
b = scatter(UElocation(jj,2),UElocation(jj,3),50,[0 0.5 0],'x');
str = [str; string(AssignCell(jj,1))];
c = text(UElocation(jj,2),UElocation(jj,3),str);
end
end
end
end