MATLAB: Code below for placing tagged spheres in a box worked well before but not with R2018a version (error messages included)

bad graphics handlesMATLAB

figure;
set(0,'ShowHiddenHandles','on')
set(gcf,'Renderer','OpenGL');set(gcf,'Color','k');set(gca,'Color','k');
set(gcf,'Colormap',colma); light; lighting gouraud;shading flat ;
daspect([1 1 1]); grid off; axis tight;%box on
[xx yy zz] =sphere(25);
X=xx;Y=yy;Z=zz;
hold on;
bad handle
Error in surf (line 86)
cax = newplot(cax);
Error in prolawat (line 593)
surf(X,Y,Z,'Tag',aa,'UserData',j)
for j=1:numat
% bb=num2str(j);
aa=atnam(j) ;ii=strfind(atom,aa) ; r=atradi(ii);
px=x(j); py=y(j) ;pz=z(j);
X=xx*r+px; Y=yy*r+py; Z=zz*r+pz;
surf(X,Y,Z,'Tag',aa,'UserData',j)
hold on
end
hc=findobj('Type','Surface','Tag','C');
set(hc,'EdgeColor','none','FaceColor',colma(1,:))
hn=findobj('Type','Surface','Tag','N');
set(hn,'EdgeColor','none','FaceColor',colma(2,:))
ho=findobj('Type','Surface','Tag','O');
set(ho,'EdgeColor','none','FaceColor',colma(3,:))
hs=findobj('Type','Surface','Tag','S');
set(hs,'EdgeColor','none','FaceColor',colma(4,:))
hw=findobj('Type','Surface','Tag','W');
set(hw,'EdgeColor','none','FaceColor','b');
hsu=findobj('Type','Surface');

Best Answer

The correct code is: [xx yy zz] =sphere(25); X=xx;Y=yy;Z=zz; figure; set(0,'ShowHiddenHandles','on') set(gcf,'Renderer','OpenGL');set(gcf,'Color','w');set(gca,'Color','w'); set(gcf,'Colormap',colma);
aa=atnam(1) ;ii=strfind(atom,aa) ; r=atradi(ii);
px=x(1); py=y(1) ;pz=z(1);
X=xx*r+px; Y=yy*r+py; Z=zz*r+pz;
h=surf(X,Y,Z,'Tag',aa,'UserData',1);
hold on;
for j=2:2000 % bb=num2str(j); aa=atnam(j) ;ii=strfind(atom,aa) ; r=atradi(ii); px=x(j); py=y(j) ;pz=z(j); X=xx*r+px; Y=yy*r+py; Z=zz*r+pz; h= surf(X,Y,Z,'Tag',aa,'UserData',j);
end
hold on;
light; lighting gouraud;shading flat ;
daspect([1 1 1]); grid off; axis off;box off
hc=findobj('Type','Surface','Tag','C');
set(hc,'EdgeColor','none','FaceColor',colma(1,:))
hn=findobj('Type','Surface','Tag','N');
set(hn,'EdgeColor','none','FaceColor',colma(2,:))
ho=findobj('Type','Surface','Tag','O');
set(ho,'EdgeColor','none','FaceColor',colma(3,:))
hs=findobj('Type','Surface','Tag','S');
set(hs,'EdgeColor','none','FaceColor',colma(4,:))
hw=findobj('Type','Surface','Tag','W');
set(hw,'EdgeColor','none','FaceColor','b');