Plotting temperature contours from txt file

Hello to everyone,
I am new here and I am new at all.
I have a set of data in txt file. For example something like this:
x y z
30 50 5
32 48 6
28 45 10
22 49 8
The points are scattered because are collected from some weather stations in different places. x is longitude and y latitude and z temperature.
1.I would like to know if there is any way to read the data from this txt file and to plot contours using an interpolation method (for example IDW).
2.At the same time I would like to plot the corresponding coastline on the background.
Thanks on account,
please for more clarifications just ask me.

2 Comments

Could you attach an example data file? Due to the formatting, your data looks like a one dimensional vector. Thanks!

Sign in to comment.

Answers (1)

To help you get started, I found some examples in the documentation about interpolation of data using the scatteredInterpolant function. You can find the links below. In the first link, check out the section entitled, "2-D Interpolation." In the second link, you can find additional examples and other methods for what you're trying to do.
Also, you might want to pay attention to the selected extrapolation method. More information can be found in the documentation for scatteredInterpolant.
As far as the importing of your data, I would use the tdfread function. To find out more:
doc tdfread
Good luck!

4 Comments

Note: scatteredInterpolant is quite new. Look at triscatteredinterp if you have R2012* or earlier.
I followed the very usefull instructions that you gave and i wrote these commands:
>> type data.dat
>> tdfread('data.dat',',')
>> plot3(x,y,z,'.','markersize',12)
>> xlabel('Longitude'), ylabel('Latitude'), zlabel('Depth in Feet')
>> grid on
>> figure
>> [xi, yi] = meshgrid(25:1:45, 13:1:22);
>> zi = griddata(x,y,z, xi,yi);
>> surf(xi,yi,zi);
>> figure
>> [c h] = contourf(xi,yi,zi, 'b-');
>> clabel(c,h);
>> xlabel('Longitude'), ylabel('Latitude')
And I have a quite nice interpolation of my data. Really thank you for this piece of advice.
The last problem that i have is about how to plot on the background the map's coastline.
I downloaded the M_Map from here (<http://www.eos.ubc.ca/~rich/map.html>) but I have two problems:
1. I can't plot the coastline and the contours in the same image.
2. I can't plot high resolution coastline because the NOAA's site, from which I could get it, is down because of the known crisis. Are there alternative ways or anyone have the files of this high res coastline script?
Thank a lot..
You can read in your image with the imread function. To keep things simple and to prevent the image from masking the contour plot, you should plot the image first and then plot the contours and data. You can use imagesc to display your coastline image with the same scale as your data.
Finally, since you most likely want a 2-d image in the end, you can plot and ignore the temperature data points. (Removing the z: plot(x,y,'.','markersize',12)).
Hope this helps!
Thank you Jonathan for the reply again.
Would it be easy if you gave me an example of these two command that you mentioned?
The commands for plotting the coastline are i.e.:
>> m_proj('lambert','long',[30 50],'lat',[15 20],'rectbox','on'); %determine the boundaries
>> m_gshhs_i('color','k'); %plot the map
So m_gshhs_i is the file that is used for plotting the coastline.
P.S. Finally NOAA opened its site and i downloaded the high resolution coastline.

Sign in to comment.

Asked:

on 16 Oct 2013

Commented:

on 18 Oct 2013

Community Treasure Hunt

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

Start Hunting!