titlestr=strcat('Number of VCSELs = ',num2str(size(data,2)),' Number of failures = ',num2str(NFail))
You don't show data so can't help debug that without more context.
But, the title() call simply passes the text string titlestr to the function, not the variable of that name--remove the quotes.
titlestr=sprintf('Number of VCSELs = %d. Number of failures = %d',size(data,2),NFail);
is just a little cleaner way to write/format the desired string; you'll have to uncover the root cause for the error or post more details on it...