Assign discrete values to meshgrid elements

9 ビュー (過去 30 日間)
Ritwik Rakshit
Ritwik Rakshit 2019 年 2 月 12 日
コメント済み: Walter Roberson 2019 年 2 月 12 日
I have a system of differential equations that takes in a pair of scalars (say C and D) and outputs a scalar E after evaluating the system numerically. I'm able to generate multiple E-values for an array of C- and D-values by using nested for loops. How can I plot the resulting values as a surface against a grid of the independent variables, rather than as a 3D scatter plot?
E is essentially a function of C and D, but cannot be expressed in closed form and must be evaluated numerically.
for i=1:n
C=0.1*i;
for j=1:n
D=0.01*j;
while ti<to
[t, y]=ode23(@myFunction, [ti to], [0; 0; 0]);
E(i,j)=y(end, 2);
end
end
end
% The following code will work, but the axes won't be oriented correctly
[C,D]=meshgrid(0:0.1:0.1*n,0:0.01:0.01*n);
surf(C,D,E);

採用された回答

Walter Roberson
Walter Roberson 2019 年 2 月 12 日
Switch to surf(C, D, E.') or else change meshgrid to ndgrid()
  2 件のコメント
Ritwik Rakshit
Ritwik Rakshit 2019 年 2 月 12 日
Transposing worked perfectly. Is there any documentation about the interaction of meshgrid and surf, or why transposition is necessary?
Walter Roberson
Walter Roberson 2019 年 2 月 12 日
The syntax is surf(X, Y, Z) , and all three matrices must be the same size. But in MATLAB X is the rows and Y is the columns .
[C, D] = meshgrid( 1:M, 1:N)
gives C as being N x M but
for i : M
for j = 1 : N
E(i, j) = something
end
end
gives E as M x N.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeSurface and Mesh Plots についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by