Borrar filtros
Borrar filtros

Confused about syntax of contour function

1 visualización (últimos 30 días)
Giles_T_R_Abbbit
Giles_T_R_Abbbit el 11 de Dic. de 2015
Comentada: John D'Errico el 12 de Dic. de 2015
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?

Respuesta aceptada

Walter Roberson
Walter Roberson el 11 de Dic. de 2015
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.

Más respuestas (1)

John D'Errico
John D'Errico el 11 de Dic. de 2015
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 comentarios
Giles_T_R_Abbbit
Giles_T_R_Abbbit el 12 de Dic. de 2015
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 el 12 de Dic. de 2015
If your data is really just an unrolled rectangular array, then reshape will suffice, as you appear to have found.

Iniciar sesión para comentar.

Categorías

Más información sobre Contour Plots en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by