필터 지우기
필터 지우기

How to plot contour of three parameters in two dimensions?

조회 수: 2 (최근 30일)
Xel Ch
Xel Ch 2018년 6월 27일
편집: Xel Ch 2018년 6월 28일
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.

답변 (1개)

Shweta Singh
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!
  댓글 수: 1
Xel Ch
Xel Ch 2018년 6월 28일
편집: Xel Ch 2018년 6월 28일
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)

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Contour Plots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by