How to make a 2D contour Map
조회 수: 8 (최근 30일)
이전 댓글 표시
Hello,
I am given a text file with three columns of various lengths. The first column is an 'x' value, the second column is a 'y' value, the third column is a 'z' (heights) value.
My goal is to make a 2D contour map using these three columns of data. The data I have looks a little organised, but they're mostly scattered. I have attached a picture on what it sort of looks like.
Each of those dots have a 'z' (height) value. Below is a sample of data I could have.
X Y Z
10 10 07
10 20 10
20 10 09
20 20 13
13 13 08
15 16 10
The goal is to use those six points for a 2D contour map. Bare in mind that I cannot hard code this. Since next time, I could be given 10 points to work with, or 20, or 50, or even a hundred.
Cheers for your help! I look forward to seeing your solutions.
댓글 수: 0
답변 (1개)
Astha Singh
2019년 3월 14일
If you want to obtain the above plot, you can use the scatter function to plot marker points at the corresponding x and y co-ordinates. Also, if you want to add text along with the marker points, you can use the text function.
Please see the below attached code for reference:
x = [10,10,20,20,13,15];
y = [10,20,10,20,13,16];
z = [7,10,9,13,8,10];
Z = num2str(z');
Zf = cellstr(Z);
scatter(x,y,'filled')
text(x+0.1, y+0.1, Zf)
Depending in the format of the input text file, the values of x, y and z can be read, using one the different methods listed in the link below:
참고 항목
카테고리
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!