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

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

Respuestas (1)

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 comentarios

There is no repetetive coordiante in my set of data. So using "unique" would not reduce the size of my vectors. And meshgrid keeps complaining about the maximum array size preference.
%%unstructured
dt = delaunayTriangulation(x,y) ;
tri = dt.ConnectivityList ;
figure
trisurf(tri,x,y,z)
It not what I want. I need a contour plot.
Just an idea: is there any way to compress the vectors accordingly ? Like I have X,Y,Mach form OpenFoam and an analytical solution from Matlab: x,y, mach. This analytical solution is much lighter than OpenFoam dat. Something that says: take the x and y from Matlab and find (maybe interpolation is necessary there) the corresponding Z in Mach file. Thus, I would have x, y and a reduced set of Mach.
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.
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.

Iniciar sesión para comentar.

Categorías

Más información sobre Contour Plots en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

el 8 de Sept. de 2020

Comentada:

el 26 de Oct. de 2020

Community Treasure Hunt

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

Start Hunting!

Translated by