How to plot contour of three parameters in two dimensions?

5 visualizaciones (últimos 30 días)
Xel Ch
Xel Ch el 27 de Jun. de 2018
Editada: Xel Ch el 28 de Jun. de 2018
Hi, I am wondering if it is possible to plot magnitude of events along with their latitudes and longitudes in a contour plot? I have gotten code for contours to run successfully a few times, but this only works when I write the Z as a function of x and y. However, in what I am trying to achieve, the three variables are independent of each other. I think this could work if I tried a 3D Contour plot, but I am trying to plot in 2 Dimensions, so I do not think contour3 is an option.
I am attaching a simplified version of my code to show what I am trying to achieve. Thank you!
x = 1;
y = 4;
z = 5;
[X, Y]= meshgrid(x, y);
contour(X,Y,z)
Error using contourf (line 57)
Z must be at least a 2x2 matrix.

Respuestas (1)

Shweta Singh
Shweta Singh el 28 de Jun. de 2018
'contour' and 'contour3' can work with independent Z as long as all the conditions are satisfied. For instance, X,Y can't be scalars and Z must be at least a 2x2 matrix. Read this documentation for details and exact working of this function: https://www.mathworks.com/help/matlab/ref/contour.html
Following is a working code:
x = [1 2];
y = [1 3];
[X,Y] = meshgrid(x,y);
z = [2 5];
Z = diag(z);
contour(X,Y,Z)
Hope this helps!
  1 comentario
Xel Ch
Xel Ch el 28 de Jun. de 2018
Editada: Xel Ch el 28 de Jun. de 2018
Hi Shweta, thank you very much for your answer! This part seems to work, although the lines are straight instead of circular like they appear in other contour plots. Do you know how I could address this? I don't think the contour documentation addresses multiple independent variables.
I am also trying to plot contours around multiple points. But when I insert more values into the code you gave me, I am given a series of straight contour lines that overlap with each other, which does not look right. I used random values, but regardless, I will attach the code I used. Any tips would be appreciated, thank you!
x = [1 2 4 7 3 9 2 ];
y = [1 3 3 8 5 2 9 ];
[X,Y] = meshgrid(x,y);
z = [2 5 2 4 5 6 1 ];
Z = diag(z);
contour(X,Y,Z)

Iniciar sesión para comentar.

Categorías

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

Community Treasure Hunt

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

Start Hunting!

Translated by