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