satheeshmenon
8th January 2005, 06:20 AM
need help to plot contours in matlab
rocksea
8th January 2005, 09:35 AM
You may have to specify for what purpose. [Like do you need
to plot over a map, or plot simple contours on a X-Y plane?]
Here is a simple method to plot filled contours in matlab from
ascii data
Suppose the data is as given below in 3 columns. (attached:data.txt)
1.distance from coast. 2.depth. 3.temperature.
You have to make a grid using 'meshgrid' and then grid the data using
'griddata' and then contour it using 'contour' (or 'contourf')
You can use the matlab code below to plot the contours
%-----------------------------------------
data=load('C:\data.txt'); %loading the data from a file
dist=data(:,1); %assigning the 1st column to distance
depth=data(:,2); %assigning 2nd column to depth
temp=data(:,3); %assigning 3rd column to temperature
[x y]=meshgrid(0:100:400,0:50:200); %creating a new grid
%minimum value:increment:maximum value of x and y axis grid
[xi,yi,zi]=griddata(dist,depth,temp,x,y,'cubic');
%gridding the temperature data to the above grid.
%‘cubic’ or any other interpolation methods can be used
contourf(xi,yi,zi); %plotting the contour
set(gca,'YDir','reverse'); %reverses the yaxis direction to
%give a realistic view of the isotherms from the coast
%-----------------------------------------
Do ask for further expansions of this code.