フィルターのクリア

Confused about syntax of contour function

1 回表示 (過去 30 日間)
Giles_T_R_Abbbit
Giles_T_R_Abbbit 2015 年 12 月 11 日
コメント済み: John D'Errico 2015 年 12 月 12 日
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?

採用された回答

Walter Roberson
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.

その他の回答 (1 件)

John D'Errico
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 件のコメント
Giles_T_R_Abbbit
Giles_T_R_Abbbit 2015 年 12 月 12 日
Thanks for the comment - I will have a look on the file exchange for the tools you mention.
To be clear however, in order to visualise the surface formed by my data, I have re-structured my data to form a regular grid, as guided in the Matlab help documentation.
John D'Errico
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 ExchangeContour Plots についてさらに検索

タグ

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by