How to plot contour of three parameters in two dimensions?
5 次查看(过去 30 天)
显示 更早的评论
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.
0 个评论
回答(1 个)
Shweta Singh
2018-6-28
'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!
另请参阅
类别
在 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!