Matlab contour plot with color

조회 수: 12 (최근 30일)
mukesh bisht
mukesh bisht 2021년 5월 26일
댓글: Star Strider 2021년 5월 26일
Can anyone tell how to plot the contour like this (shown in fig) in MATLAB

답변 (2개)

Cris LaPierre
Cris LaPierre 2021년 5월 26일

Star Strider
Star Strider 2021년 5월 26일
Use the contourf function, and choose the colormap that most closely represents what you want (for shades-of-gray, the gray colormap would lilkely be best).
  댓글 수: 2
mukesh bisht
mukesh bisht 2021년 5월 26일
I have the following condition: matrix X: x coordinates, matrix Y : y coordinates, matrix Z : velocity corresponding to each (x,y).
While using contourf function it shows following error "Z must be at least a 2x2 matrix."
Star Strider
Star Strider 2021년 5월 26일
It appears that all three of them are vectors, or that error would not appear.
One possibility is that the vectors represent gridded data, so simply using the reshape function with each of them (with the same reshape parameters for each vector) would work. To use it, it would be necessary to know at least one dimension of the matrix (rows or columns). There are several ways to do that, one is using the unique function on either ‘x’ or ‘y’ and determining the number of unique values by the number of elements in the first output.
Alternatively, try something like this —
N = 50;
xv = linspace(min(x), max(x), N);
yv = linspace(min(y), max(y), N);
[X,Y] = ndgrid(xv, yv);
Z = griddata(x, y, z, X, Y);
figure
contourf(X, Y, Z)
colormap('gray')
Change ‘N’ (or use different values for each linspace call), depending on the result you want.

댓글을 달려면 로그인하십시오.

카테고리

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