Post processing data and make contour plot: Error using contour (line 48) Z must be at least a 2x2 matrix to plot contour lines
12 views (last 30 days)
I have raw data coming from OpenFoam. The data is about all the cell points of a slice of my geometry. So, I have 3 colums and 384000 raws for 3 parameters: X,Y and the Mach number. I want to make a contour plot of that. So, I imported the data from the text file to Matlab. I made 3 vectors out of it. I use Contour(X,Y,Mach,int). The size of X, Y and Mach are: 1x384000. And the problem arises there:
Error using contour (line 48)
Z must be at least a 2x2 matrix.
I dont understand why contour must work with matrices and not vectors. I saw in the forums that people suggest to use "meshgrid". But in my case, as the data set is already huge, meshgrid leads to the following error:
Error using repmat
Requested 384000x384000 (1098.6GB) array exceeds maximum array size preference.
Creation of arrays greater than this limit may take a long time and cause MATLAB
to become unresponsive. See array size limit or preference panel for more
So, what is the best way to make contour work with raw data without generating a huge amount of data unnecessarily.
KSSV on 8 Sep 2020
Let A be your 384000*3 matrix.
x = A(:,1) ; y = A(:,2) ; z = A(:,3) ;
xi = unique(x) ; yi = unique(y) ;
[X,Y] = meshgrid(xi,yi) ;
Z = reshape(z,size(X)) ;