convert plot3 to contour plot

6 ビュー (過去 30 日間)
MOOSE
MOOSE 2020 年 1 月 17 日
回答済み: Star Strider 2020 年 1 月 17 日
Hi,
I have a novice question in matlab.
Say that I have some matrix
a = [1 2 3; 4 5 6; 7 8 10; 11 12 13]
I can plot this in 3d where column 1 is the x-axis, column 2 is the y-axis, and column 3 is the z-axis, by writing
plot3(a(:,1),a(:,2),a(:,3),'.').
However, I also want to make a contour plot where I have column 1 along the x-axis, column 2 along the y-axis, and column 3 represents the heights above the z = 0 plane. To do this I have to reshape my data somehow so that I can write something like
contourf(X,Y,Z).
How can I do this efficiently?

回答 (1 件)

Star Strider
Star Strider 2020 年 1 月 17 日
Use the griddata function:
a = randi(9, 10, 3);
x = a(:,1);
y = a(:,2);
z = a(:,3);
xv = linspace(min(x), max(x), 6);
yv = linspace(min(y), max(y), 8);
[X,Y] = meshgrid(xv, yv);
Z = griddata(x,y,z,X,Y);
figure
contourf(X, Y, Z)
colorbar
The griddata function had problems with your original ‘a’ matrix, so I created one it would work with.

カテゴリ

Help Center および File ExchangeContour Plots についてさらに検索

製品


リリース

R2017a

Community Treasure Hunt

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

Start Hunting!

Translated by