Plotting a vectorial function over a meshgrid.

Dear MathWorks Community, I would like to plot a vectorial function called mysurface over a 2D area like [0,2]x[0,1]. Basically the function describes a deformation of [0,2]x[0,1] into 3D. When defining a meshgrid [X,Y] = meshgrid(0:0.1:2, 0:0.1:1) I can't simply write mysurface([X,Y]), since [X,Y] isn't a vector. How do I handle that? Also I would like to plot the resulting surface, but using surface[X,Y,Z] wouldn't make sense. I need something like p=mysurface([X,Y]) and plot with surface(p(1),p(2),p(3)) but over all points of the grid. Thank you in advance.

댓글 수: 7

Guillaume
Guillaume 2018년 10월 23일
What is a vectorial function? What inputs does your function need?
Philipp Tscherner
Philipp Tscherner 2018년 10월 23일
편집: Philipp Tscherner 2018년 10월 23일
With that i mean a function from R^2 to R^3. The function mysurface needs a 2D vector p in [0,2]x[0,1] and gives back a vector in R^3.
Guillaume
Guillaume 2018년 10월 23일
So does your function takes one 1x2 (or 2x1) input or two scalar inputs (dx, dy)? Is your function vectorised in that you can pass an array of vectors (so a Mx2 or 2xM array in the case of one input, or 2 Mx1 inputs for two inputs)?
whatever the answer it shouldn't be too hard to call your function with all the meshgrided vectors. How you'd display the result however, I have no idea. Maybe have 3 plots p(1) against (x, y), p(2) against (x, y), and p(3) against (x,y).
KSSV
KSSV 2018년 10월 24일
Do you have specific input and pictorial example?
Philipp Tscherner
Philipp Tscherner 2018년 10월 24일
편집: Philipp Tscherner 2018년 10월 24일
Input is a 2x1 vector and the function gives the 3x1 coordinates of the deformed 2D point. Visually it's referred to some plate bending problem. I now simply summed over all x and y in my mesh and created new matrizes Z1, Z2, Z3 and used surf(Z1, Z2, Z3). This seems to work pretty well, I can post the code later, if you are interested.
Guillaume
Guillaume 2018년 10월 24일
It sounds like your input was actually a 3D mesh with all points having Z=0 and your output was the resulting 3D mesh after deformation and you're just plotting that resulting 3D mesh.
In which case, yes it's fairly straightforward. However, I don't understand how summing the X and Y coordinates of the input mesh helps.
Please don't close questions that have an answer. Even if the answer is not what you were looking for.
Yes you could identify (x, y) = (x, y, 0). As already said I created 3 matrices Z1, Z2, Z3. Mysurface gets the 2D mesh point (x, y) and returns the deformed point p. Summing over all x, y (the indices i, j have to run accordingly) I can define my deformed surface by Z1, Z2, Z3 and finally plot the resutling surface. Although I know it works, I'm not sure if that's the prettiest way to solve the problem:
p = mysurface(x, y)
Zk(i, j) = p(k)
surf(Z1, Z2, Z3)

댓글을 달려면 로그인하십시오.

답변 (1개)

KSSV
KSSV 2018년 10월 24일

0 개 추천

V = [2 3] ;
L = V(1) ; % length of the plate
B = V(2) ; % breadth of the plate
N = 100 ;
x = linspace(0,L,N) ;
y = linspace(0,B,N) ;
[X,Y] = meshgrid(x,y) ;
mesh(X,Y)

카테고리

제품

릴리스

R2017a

질문:

2018년 10월 23일

편집:

2018년 10월 24일

Community Treasure Hunt

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

Start Hunting!

Translated by