Azzera filtri
Azzera filtri

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

1 visualizzazione (ultimi 30 giorni)
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

Risposta accettata

KSSV
KSSV il 30 Gen 2019
Modificato: KSSV il 30 Gen 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 Commenti
KSSV
KSSV il 30 Gen 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 il 30 Gen 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

Accedi per commentare.

Più risposte (0)

Prodotti


Release

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by