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

1 次查看(过去 30 天)
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

回答(1 个)

KSSV
KSSV 2020-9-8
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 个评论
KSSV
KSSV 2020-9-8
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 2020-10-26
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.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Contour Plots 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by