Question

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.

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top