MATLAB: Does the numbering for the SaveAs function begin to use symbols after a certain number of figures

figureMATLABpngsaveasstr2cat

Hello,
I am trying to save a series of figures under different lists (up, down, left right, etc.), and want the titles to start from 1 for every list. To do this, I have been using:
for nn = (1:119)
figure
if nn <= 2,
title(['Down Subject ' ,num2str(nn)])
saveas(figure(nn),strcat('Down Subject ', num2str(nn)),'png');
elseif nn <= 5,
title(['Up Subject ',num2str(nn)-2])
saveas(figure(nn),strcat('Up Subject ', num2str(nn)-2),'png');
elseif nn <= 16,
title(['Back Subject ',num2str(nn)-5])
saveas(figure(nn),strcat('Back Subject ', num2str(nn)-5),'png');
elseif nn <= 44,
title(['Left Subject ',num2str(nn)-16])
saveas(figure(nn),strcat('Left Subject ', num2str(nn)-16),'png');
elseif nn <= 74,
title(['Right Subject ',num2str(nn)-44])
saveas(figure(nn),strcat('Right Subject ', num2str(nn)-44),'png');
else
title(['Away Subject ',num2str(nn)-74])
saveas(figure(nn),strcat('Away Subject ', num2str(nn)-74),'png');
end
end
which works for the first few iterations. Once it hits Back Subject #5, however, it begins generating filenames with symbols instead of numbers (e.g. Back Subject,,.png). What changes can we make to the numbering to correct this? The problem does not persist once I remove the subtractions, but there are simply so many figures that renaming them is very inconvenient. Please let me know if there are any additional detail we can provide.
Thank you, AL

Best Answer

Why are you subtracting integers from the character string representation of nn ?
I would suggest to you that instead of num2str(nn)-something that you want num2str(nn-something)