How to create contour plot to show height?

조회 수: 5 (최근 30일)
Muhammad Qaisar Fahim
Muhammad Qaisar Fahim 2022년 3월 18일
댓글: DGM 2022년 3월 21일
I want to create a countour plot such that my x axis and y axis are the coordinates of the plane and my z axis is height. I want to creat a 2b plot (contour) such that my height is differentiated with color. My z value has no relation with xy value other that the first value of z is corresponding to the cobination of first two values of x and y.
For example my x, y and z vectors are:
AAA=1:1:1000;
BBB=1:1:1000;
CCC=2:2:2000;
  댓글 수: 3
Muhammad Qaisar Fahim
Muhammad Qaisar Fahim 2022년 3월 18일
The correlation is that for each pair of x and y there is a corresponding value of z but the limitataion is that we only have one to one correspondance i.e., 1st value of x and first value of y corresponds to first value of z but first value of x and 2nd value of y corresponds to nothing.
DGM
DGM 2022년 3월 18일
Okay, yeah. That's just scattered data. Walter's suggestion looks pretty good.

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

채택된 답변

DGM
DGM 2022년 3월 19일
You can always try just using griddata()
S = load('scattered.mat'); % load scattered data
n = 100;
x = linspace(min(S.x),max(S.x),n);
y = linspace(min(S.y),max(S.y),n);
[xg yg] = meshgrid(x,y); % create new grid
zg = griddata(S.x,S.y,S.z,xg,yg); % interpolate scattered data to grid
contour(xg,yg,zg) % now you can use contour(), contourf(), surf(), etc
  댓글 수: 8
Sam Chak
Sam Chak 2022년 3월 21일
Hi @DGM
His data of the position of the road (in Spherical coordinate system) was posted here in the first comment of the first answer (by @KSSV).
DGM
DGM 2022년 3월 21일
Oh. Well it doesn't make much sense spending time and confusion here then. Thanks for the heads up.

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

추가 답변 (1개)

Walter Roberson
Walter Roberson 2022년 3월 18일
  댓글 수: 2
Muhammad Qaisar Fahim
Muhammad Qaisar Fahim 2022년 3월 18일
편집: Walter Roberson 2022년 3월 19일
Hi Walter,
Error using tricontour (line 58)
Incorrect input dimensions
Error in runMatlogOSM_2nodes (line 25)
tricontour(A,B,C,1)
Eventhough I have downloaded the function and the path as
addpath(genpath('./tricontour'), '-end');
My Command line is
tricontour(A,B,C,1)
Walter Roberson
Walter Roberson 2022년 3월 19일
The first parameter to tricontour() needs to be the xy coordinates, each row being an x y pair.
The second parameter to tricontour() needs to be the triangular connectivity data.
You might want to use https://www.mathworks.com/help/matlab/ref/delaunaytriangulation.html and extract the Points and ConnectivityList properties of the result.

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

카테고리

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

태그

제품


릴리스

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by