Confused about syntax of contour function
1 次查看(过去 30 天)
显示 更早的评论
My task is very similar as to in this question - in that I have data in the form of X,Y,Z triplets and I want to find the X,Y pairs for which Z=0.
In the answer, it is stated that the zero contour can be plotted using:
[c, hc] = contour(x,y,z,[0 0],'k');
Looking at the help documents, this is one of several pieces of syntax for the function and returns the contour matrix, c, and the contour object, hc.
I get that the former holds the contour defining data.
- What is the latter - the contour object?
- [c, hc] suggests to me an array/vector. Why is this being used?
Furthermore, considering the arguments of the contour function call. If I am reading the documentation correctly:
- the first three - x, y, z - relate to the data being considered;
- the [0,0] argument of the contour function call is specifying the level of the contour - so here Z=0. Why is the number repeated? If I want the contour at level 5, do I change this argument to [5,5]?
- What does the 'k' do?
Finally, is it possible to plot the contour as a serious of markers rather than a line?
0 个评论
采纳的回答
Walter Roberson
2015-12-11
When you have multiple variables in [] on the left side of an expression, it indicates the assignment of multiple outputs. The first output goes into the first location, the second output goes into the second location, and so on. It is a list of output locations but does not imply anything about the data type or shape of each output.
The 'k' is a LineSpec, a specification of how you want the line drawn. The 'k' stands for kohl, which is a word for black -- because 'b' is already used for 'blue' and 'k' is the traditional abbreviation in printing. You will find some places that explain the 'k' as standing for 'key', the terminology used in the 4-color CMYK printing process.
The [0 0] does stand for the level and you would use [5 5] if you wanted only level 5. The double value is needed because a single value would be interpreted as requesting the corresponding number of levels -- e.g., 5 by itself would ask for 5 contour levels to be used.
The contour object is the MATLAB graphics object used to hold information about the contour plot. Like line and patch and image and barseries and uicontrol and axes and figure graphics objects, it has a number of properties; you can read about them here
You do not happen to mention which MATLAB version you are using. Current versions of MATLAB do not allow you to plot as markers instead of as lines (but do allow you to select the style of line including dashed lines). If you are using R2014a or earlier then it is possible to choose a contour routine that will return a patch() object whose properties could be changed to plot markers instead of lines.
0 个评论
更多回答(1 个)
John D'Errico
2015-12-11
Note that you claim to have data in the form of scattered triplets, (x,y,z). Contour does NOT solve this problem. That is generally known as scattered data.
However, there are several tools for contouring scattered data on the file exchange. Do a search for "tricontour" on the FEX and you should find at least two tools up there.
2 个评论
John D'Errico
2015-12-12
If your data is really just an unrolled rectangular array, then reshape will suffice, as you appear to have found.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Contour Plots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!