MATLAB: Contour from .xlsx, getting “Z must be at least a 2×2 matrix” error

contourexcel

I am trying to plot a contour of Z where the value of Z is linked to an X and Y value. X and Y are temperature and pressure and Z is the amout of a variable.
data = xlsread('data.xlsx','Sheet1','A1:C300');
x = data(:,2);
y = data(:,1);
z = data(:,3);
[X,Y]=meshgrid(x,y);
contour(X,Y,z)
Any suggestions? I have attached the excel file.
Thank you!

Best Answer

You first need to convert you z vector into a grid to use contour()
data = xlsread('data.xlsx','Sheet1','A1:C300');
x = data(:,2);
y = data(:,1);
z = data(:,3);
xg = linspace(min(x), max(x), 50);
yg = linspace(min(y), max(y), 50);
[X,Y]=meshgrid(xg,yg);
Z = griddata(x, y, z, X, Y);
contour(X,Y,Z)
Related Question