how to plot contour function

1 回表示 (過去 30 日間)
Jong Hyun Lee
Jong Hyun Lee 2022 年 4 月 1 日
コメント済み: Walter Roberson 2022 年 4 月 1 日
I want to plot a contour plot of temperatuer T, where T=x*e^y (T has x and y components)
range -50<=x<=50, 0<=y<=100
I followed the guide by matlab of plotting contour plot
(This plot was most visible)
x=linspace(-50,50);
y=linspace(0,100);
[X,Y]=meshgrid(x,y);
z=X.*exp(Y)
contour(x,y,z)
however, the given range for x and y gave me a very weired looking graph.
Hence, I change the range to make it visible
x=linspace(-5,5);
y=linspace(0,1);
[X,Y]=meshgrid(x,y);
z=X.*exp(Y)
contour(x,y,z)
Is there any mistake in first code?

採用された回答

Voss
Voss 2022 年 4 月 1 日
x = 0:10;
y = 0:0.2:2;
[X,Y] = meshgrid(x,y);
T = X.*exp(Y);
contour(X,Y,T) % using matrices X, Y
% contour(x,y,T) % same result, using vectors x, y
colorbar
  2 件のコメント
Jong Hyun Lee
Jong Hyun Lee 2022 年 4 月 1 日
編集済み: Jong Hyun Lee 2022 年 4 月 1 日
Thank you for the answer, is there any options that I can display a plot into gradation form by using contour function? not lines?
Like this?
Walter Roberson
Walter Roberson 2022 年 4 月 1 日
x = 0:10;
y = 0:0.2:2;
[X,Y] = meshgrid(x,y);
T = X.*exp(Y);
contourf(X,Y,T, 20) % using matrices X, Y
% contour(x,y,T) % same result, using vectors x, y
colorbar

サインインしてコメントする。

その他の回答 (1 件)

Walter Roberson
Walter Roberson 2022 年 4 月 1 日
xvec = linspace(0, 5, 25);
yvec = linspace(-3, 3, 25);
[X, Y] = meshgrid(xvec, yvec);
T = X .* exp(Y);
surf(X, Y, T, 'edgecolor', 'none')

カテゴリ

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by