How to generate a coordinate field, compute values for each coordinate and plot the results?

3 次查看(过去 30 天)
Hello,
first, i would like to generate a 2D coordinate field from e.g. 0/0 to 0/100, 100/100 and 100/0 with 10 steps, giving 11x11 = 121 coordinates.
My first try is:
for i = 0:10
A(:,1+2*i) = 0:10:100;
A(:,2+2*i) = (i)*10;
end
I don't like this solution, especially if I want to calculate larger fields.....
second, i would like to calculate a value for each coordinate, e.g. value = f(x,y). How can i plot the calculated values with its x,y coordinates in a 3D plot?
I would be very grateful for assistance and possible solutions!
Christopher

采纳的回答

KSSV
KSSV 2019-1-30
编辑:KSSV 2019-1-30
Read about linspace and meshgrid
x = linspace(0,100,11) ;
y = linspace(0,100,11) ;
[X,Y] = meshgrid(x,y) ;
Z = X+Y ;
surf(X,Y,Z)
  5 个评论
KSSV
KSSV 2019-1-30
Thats striaght forward.....I have given examples above......as you are using matrices ..read about element by element operations in matrices. https://in.mathworks.com/help/fixedpoint/ref/times.html
Christopher Brokmann
i still have problems to include my function... the only solution i found is with 2 loops, which has the disadvantage of a long run time epsecially for a high number of points for x and y.
x = linspace(0,1,11) ;
y = linspace(0,1,11) ;
[X,Y] = meshgrid(x,y) ;
for kk = 1:11
for nn = 1:11
Coordinate = [X(kk,nn) Y(kk,nn)];
Z(kk,nn) = f_DeltaWegPunkt(Coordinate,someConstant,...);
end
end

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Surface and Mesh Plots 的更多信息

产品


版本

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by