Clear Filters
Clear Filters

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

1 view (last 30 days)
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

Accepted Answer

KSSV
KSSV on 30 Jan 2019
Edited: KSSV on 30 Jan 2019
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 Comments
KSSV
KSSV on 30 Jan 2019
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
Christopher Brokmann on 30 Jan 2019
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

Sign in to comment.

More Answers (0)

Products


Release

R2017b

Community Treasure Hunt

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

Start Hunting!