Here are the two syntaxes that can class for contour:
From the documentation:
contour(Z,v) draws a contour plot of matrix Z with contour lines at the data values specified in the monotonically increasing vector v. The number of contour levels is equal to length(v). To draw a single contour of level i, use contour(Z,[i i]).
Time for the confession. I thought at the time we were designing contour that asking for a single contour would be rare enough to warrant having the "convenient" syntaxes that could clash. And I even know the work-around for programmers. If they wanted to specify the contour levels, they simply needed some code like this:
if length(mycontours) == 1 mycontours(2) = mycontours; end % now call the contour function
So, why don't I like this now? The code is harder to read, the intent is harder to discern, and it just feels clunky.
I can think of a bunch of possible solutions, were we to design the contour function today. These include (but certainly aren't limited to):
- two functions, 1 for number of contours, 2 for values of contours
- control number vs. level behavior with param/value pairs or some similar device
- have one of the inputs (perhaps scalar level number) be in a cell array or some other class that differs from the class for the level values input
Has the ambiguity in contour bitten you? Or one in some other MATLAB functionality? What solution do you prefer? Let me know here.
댓글을 남기려면 링크 를 클릭하여 MathWorks 계정에 로그인하거나 계정을 새로 만드십시오.