ix1 = (Xs1-x2).^2+(Ys1-y2).^2+(Zs1-z2).^2 < R2^2;
scatter3(Xs1(~ix1),Ys1(~ix1),Zs1(~ix1),20,'r','h','filled','MarkerFaceColor',[1 0 0])
hold on
ix2 = (Xs2-x1).^2+(Ys2-y1).^2+(Zs2-z1).^2 < R1^2;
scatter3(Xs2(~ix2),Ys2(~ix2),Zs2(~ix2),20,'r','h','filled', 'MarkerFaceColor',[1 0 0])
hold on
ix3 = (Xs3-x2).^2+(Ys3-y2).^2+(Zs3-z2).^2 < R2^2;
scatter3(Xs3(~ix3),Ys3(~ix3),Zs3(~ix3),20,'r','h','filled', 'MarkerFaceColor',[1 0 0])
hold on
ix4= (Xs2-x3).^2+(Ys2-y3).^2+(Zs2-z3).^2 < R3^2;
scatter3(Xs2(~ix4),Ys2(~ix4),Zs2(~ix4),20,'r','h','filled', 'MarkerFaceColor',[1 0 0])
Your code above is plotting the four sets of arrays you're selecting in the scatter3 calls -- but to write those data out you need to have saved them to local variables (or duplicate the selection again). Depending on the size of the arrays, this could create a very large file, indeed.
Do you really, really have to have a text file -- could you not use a MATLAB .mat file instead? It will have full precision of the results and be smaller. Other results will generally only have 6 or 7 digits of precision; if this is ok, then ok, but just need be aware.
ix1 = (Xs1-x2).^2+(Ys1-y2).^2+(Zs1-z2).^2 < R2^2;
X=(Xs1(~ix1); Y=Ys1(~ix1); Z=Zs1(~ix1);
scatter3(X,Y,Z,20,'r','h','filled','MarkerFaceColor',[1 0 0])
writematrix([X(:),Y(:),Z(:)],'YourFileName1.txt')
Lather, rinse and repeat for the other sets...NB: you MUST create a new and unique filename for each of the sets; I just used a sample placeholder above. Use fulfile to build a fully-qualified filename if writing to somewhere other than the current working directory.
Best Answer