Post processing data and make contour plot: Error using contour (line 48) Z must be at least a 2x2 matrix to plot contour lines

5 views (last 30 days)
Hi,
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
information.
So, what is the best way to make contour work with raw data without generating a huge amount of data unnecessarily.
Regards,
Mary

Answers (1)

KSSV
KSSV on 8 Sep 2020
Let A be your 384000*3 matrix.
x = A(:,1) ; y = A(:,2) ; z = A(:,3) ;
%%structured
xi = unique(x) ; yi = unique(y) ;
[X,Y] = meshgrid(xi,yi) ;
Z = reshape(z,size(X)) ;
figure
contour(X,Y,Z)
  5 Comments
KSSV
KSSV on 8 Sep 2020
Read about griddata. You can do interpolation and get structured grid i.e matrices. With x,y,z also you can plot contour. Search for tricontour.
Abdallah Ghazal
Abdallah Ghazal on 26 Oct 2020
Hi, I do the same kind of postprocessing of my OpenFOAM results in MATLAB. The problem I have is the long time it takes MATLAB to postprocess that data. I bieleve this is because the 'griddata' function is inside the for loop and I do have more than 100 iterations. I am wondering if there is any way to speed up the postprocessing. For your information, a simulation of 100 iterations takes about an hour of clock time. I would appreciate any assistance. Thanks.

Sign in to comment.

Categories

Find more on Contour Plots in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!