3d Plotting Using Meshgrid

2 ビュー (過去 30 日間)
onsagerian
onsagerian 2019 年 11 月 6 日
コメント済み: onsagerian 2019 年 11 月 6 日
Hello,
This is the Matlab script I designed for 3D plotting using "meshgrid". Basically, I need to make a plot a function which is given by " f " depending on two independent variables " i " and " j ". I want to keep " f " as a 2-D array. I have tried to modify my code several times, but I couldn't get an expected output. Would you help me to address the problem?
format long e
n=1:1:5;
m=1:1:10;
alpha=0.01;
A=zeros(length(n),length(m));
B=zeros(length(n),length(m));
f=zeros(length(n),length(m));
for i=1:1:length(n)
for j=1:1:length(m)
A(i,j)=i.^2/j.^3;
B(i,j)=A(i,j)/(alpha+i);
f(i,j)=B(i,j)./A(i,j);
%fprintf('%d %d %.10e %.10e %.10e\n',i,j,A(i,j),B(i,j),f(i,j));
end
end
for i=1:1:length(n)
for j=1:1:length(m)
[X,Y]=meshgrid(i,j);
%disp(f(X,Y));
mesh(X,Y,f(X,Y));
end
end

採用された回答

Daniel M
Daniel M 2019 年 11 月 6 日
Replace
for i=1:1:length(n)
for j=1:1:length(m)
[X,Y]=meshgrid(i,j);
%disp(f(X,Y));
mesh(X,Y,f(X,Y));
end
end
with
[X,Y] = meshgrid(1:length(n),1:length(m));
figure
surf(X,Y,f')
  1 件のコメント
onsagerian
onsagerian 2019 年 11 月 6 日
It works! Thank you for your help.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeChange Markers についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by