Renaming figures and tables in appendices in LaTeX

I have trouble remembering how to reset the counters for tables and figures in LaTeX. This chunk resets the figure/table numbers and adds an S in front of them (as in Figure S1). Chunk taken from: http://bytesizebio.net/2013/03/11/adding-supplementary-tables-and-figures-in-latex/

\newcommand{\beginsupplement}{
  \setcounter{table}{0}
  \renewcommand{\thetable}{S\arabic{table}}%
  \setcounter{figure}{0}
  \renewcommand{\thefigure}{S\arabic{figure}}%
}

Then, when your supplement starts, just add the line:

\beginsupplement