MATLAB: Do CONTOUR and CONTOURC produce different results in MATLAB 7.8 (R2009a)

contourcontourcdifferencedifferentMATLABoutputresultsame

The CONTOURC documentation states that: "contourc calculates the contour matrix C used by contour, contour3, and contourf.". So I am wondering why the following code does not produce the same results for C1 and C2:
[C1,h] = contour(peaks)
C2 = contourc(peaks)

Best Answer

When using CONTOUR and CONTOURC the results C1 and C2 might indeed differ:
[C1,h] = contour(peaks)
C2 = contour(peaks)
However C1 and C2 are not necessarily expected to be exactly the same. As of MATLAB 7.4 (R2009a) the CONTOUR documentation provides the following explanation:
[C,h] = contour(...) returns a contour matrix, C, derived from the matrix returned by the low-level contourc function, and a handle, h, to a contourgroup object. clabel uses the contour matrix C to create the labels. (See descriptions of contourgroup properties.)
In this context "derived" indicates the matrices are not exactly the same, which is due to numerical precision as well as post-processing that occurs in CONTOUR. The same holds true for the sentence: "contourc calculates the contour matrix C used by contour".