How to make a 2D contour Map
5 views (last 30 days)
Show older comments
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.
![MATLABHELP.png](https://www.mathworks.com/matlabcentral/answers/uploaded_files/207562/MATLABHELP.png)
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 Comments
Answers (1)
Astha Singh
on 14 Mar 2019
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:
See Also
Categories
Find more on Contour Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!