Hello, I am making a code to make GIF files out of a series of superimpositions of images but I'm not able to add a title that changes for every frame of the GIF. The code works perfectly for making GIFs with a colorbar, but no way I can add the title. Could someone help me? Thank you!
Here's the code:
figure4=figure(4)set(gcf, 'Units', 'Normalized', 'OuterPosition', [0 0 1 1]);M4=max((max(reshape(BBIO,503*647,146))'));% Setting transparency conditions: if the pixel signal is > 0, then in matrix A it is marked as 1 (transparent). Otherwise it is 0 (opaque)
R4=reshape(BIO,503*647,146);X=15;for j=1:146; for i=1:503*647; if R4(i,j)<X; R4(i,j)=0; else R4(i,j)=1; end endendA4=reshape(R4,503,647,146);% Generating images and saving them into GIF
for i=1:146title(['\lambda=',sprintf('%d',2*i+678),'nm']) %%% I TRIED THIS BUT GIVES ME ONLY THE VALUE FOR i=1 %%%
ax1 = axes('Parent',figure4);ax2 = axes('Parent',figure4);clims=[X M4];i1=imagesc(BIO(:,:,i),'Parent',ax2,clims);colormap(ax2,jet);hold on;set(i1,'alphadata',A4(:,:,i));colorbar;c3=colorbar;w=c3.Position;c3.Position=[0.860954412414402,0.110072689511942,0.030111111111111,0.815160955347871]set(c3,'YTick',[])hold on;imagesc(BIO_US_double(:,:,i),'Parent',ax1);colormap(ax1,gray);daspect(ax1,[1 1 1]);daspect(ax2,[1 1 1]);set(ax1,'Visible','off');set(ax2,'Visible','off');hold off;% gif utilities
drawnow; frame = getframe(4); im = frame2im(frame); [imind,cm] = rgb2ind(im,256); outfile = 'BIO.gif'; % On the first loop, create the file. In subsequent loops, append.
if i==1 imwrite(imind,cm,outfile,'gif','DelayTime',0,'loopcount',inf); else imwrite(imind,cm,outfile,'gif','DelayTime',0,'writemode','append'); endendclear('ax1','ax2','clims','i','j','lambda','M4','R4','A4','figure4','i1');
Best Answer