[Tex/LaTex] Reference to figures in appendix is not printed properly

appendiceschngcntrcross-referencingnumbering

When citing a figure in a section in my report body, the reference prints the correct number:

 Figure\ref{fig:UML} illustrates complexity arising from the non-modularity of the existing design:

 Figure 5.1.1 illustrates complexity arising from the non-modularity of the existing design:

However, the reference in my appendices fails to print out the reference in the same manner:

 \appendix
 \backmatter
 %...
 Figure \ref{fig:mvcmodel} is a visual representation of the pattern:

 Figure B is a visual representation of the pattern:

I am currently using chngcntr package to number my figures and tables in my
\listoffigures and \listoftables, and I want the reference in appendices to follow the same numbering scheme as my table of contents.

I am attaching my document class:

  \let\appendix@rig\appendix
  \renewcommand{\appendix}{%
     \@mainsect%
         \ifthenelse{\boolean{uwwkrpt@math}}{%
             \renewcommand{\@secdotzerostart}[1]{\renewcommand{\dotzero}{}}
             \renewcommand{\@secdotzeroend}[1]{}
      }{}%
         \ifthenelse{\boolean{uwwkrpt@ece}}
             {\renewcommand{\@appendixtitle}{Appendix }}{}
  \appendix@rig%
  }
  \newcommand{\backmatter}{%
  \clearpage
  \@notmainsect%
  \ifthenelse{\boolean{uwwkrpt@math}}%
     {\renewcommand{\section}{\clearpage\section@rig}}{}%
   }

Best Answer

A \caption command is required for referencing to the label. If you don't have a caption, the reference would point to the most recent possible place, which can be the section containing the figure. Here you are in the appendix and in section B, so you would get the reference to B.

If you don't use \caption and \label in the right order (\caption at first), it would have the same effect, as egreg commented.

The problem is very similar to the one in this question: autoref points to section instead of figure or table.