0

I have data (31,3), column 1 is time (T), column 2 is altitude (H) and column 3 is parameter (P) I want to plot as contourf. How do I make contourf of P? as function of T and H. Thank you in advance. T is between 18 and 24, H is between 150 and 600.

1 Answers1

0

So I assume you want to create a contour plot from irregular data. The basic procedure is here. For your case,

t = data(:,1);
h = data(:,2);
p = data(:,3);

n_elem = 33;
tlin = linspace(min(t),max(t),n_elem);
hlin = linspace(min(h),max(h),n_elem);

[T,H] = meshgrid(tlin,hlin);

% use this for new MATLAB
f = scatteredInterpolant(t,h,p);
P = f(T,H);

% use this for older MATLAB
P = griddata(t,h,p,T,H);

contourf(T,H,P) 

EDIT:

If your are using older version MATLAB, it may not have scatterInterpolant. Then, use griddata instead.

ysakamoto
  • 2,512
  • 1
  • 16
  • 22
  • Thank you @ysakamoto for you suggestios, but still not work because type of input argument is 'double'. Undefined function or method 'scatterInterpolant' for the type – user3346361 Apr 21 '14 at 02:32
  • which version of matlab are you using? – ysakamoto Apr 21 '14 at 02:36
  • I forgot another question. If I have more than parameter like P, says P2 and P3 and want to add in the same contour plot. Should I also define P2 = griddata(t2,h2,p2,T2,H2) and P3 = griddata(t3,h2,p2,T2,H2)? and how I merge P2 and P3 to P? – user3346361 Apr 21 '14 at 04:48
  • how would you add more than one variable in a contour plot? your contours will intersect with each other and get messy. – ysakamoto Apr 21 '14 at 04:53
  • Actually, I need to plot longer data. Time (T) extended from daily to monthly so it will be contour of monthly (T), altitude (H) and P. – user3346361 Apr 22 '14 at 01:36