plot simple 2D-surface from 2D-vector valued function

28 次查看(过去 30 天)
It's really frustrating me that I manage to transfer it into 3D and not 2D. Her'es what I'm talking about:
I got a function f: (u,v) ->(u*sin(v),u*cos(v),u^2) where u in (0,1) and v in (0,2*pi)
What's working flawlessly:
[u,v] = meshgrid(linspace(0,1),linspace(0,2*pi));
x = u.*sin(v); y = u.*cos(v); z = u.^2;
mesh(x,y,z)
But what IF I just want to plot x and y without z? According to my imagination a filled circle should be the outcome.
mesh(x,y)
is not supporting that point of view
  2 个评论
Niklas Kurz
Niklas Kurz 2021-5-2
编辑:Niklas Kurz 2021-5-2
z = zeros(size(u))
would fullfill the purpose, but the object still is living in 3D
Niklas Kurz
Niklas Kurz 2021-5-2
What also seems to work:
u = linspace(0,1); v = linspace(0,2*pi)
v = v';
x = u.*sin(v); y = u.*cos(v);
plot(x,y)
But also not right what I'm striving for because points are connected as line.

请先登录,再进行评论。

采纳的回答

Scott MacKenzie
Scott MacKenzie 2021-5-2
编辑:Scott MacKenzie 2021-5-3
Seems you just want the points and not the lines connecting the points. In that case, just add a line specifier to plot to specify plotting just the points:
u = linspace(0,1); v = linspace(0,2*pi)
v = v';
x = u.*sin(v); y = u.*cos(v);
plot(x,y,'.'); % '.' is a line specifier -- just the points are plotted
Here's the output, zoomed in a bit to show that only the points are plotted:
Having just re-read your original question, perhaps you want a "filled circle". In that case, use patch instead of plot:
u = linspace(1, 0); % NOTE: largest circle first
v = linspace(0, 2*pi);
v = v';
x = u.*sin(v);
y = u.*cos(v);
c = 1:100;
patch(x, y, c, 'edgecolor', 'none');
The circle edges are turned off to prevent the lines from dominating the visual result. Note as well that the circle patches are created largest to smallest. This is needed so new circles are visible on top of previous circles.

更多回答(1 个)

Adam Danz
Adam Danz 2021-5-3
Perhaps you're just looking for a top-down view of the 3D axes
[u,v] = meshgrid(linspace(0,1),linspace(0,2*pi));
x = u.*sin(v); y = u.*cos(v); z = u.^2;
mesh(x,y,z)
view(2) % <---- set view
xlabel('x axis')
ylabel('y axis')

类别

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

标签

Community Treasure Hunt

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

Start Hunting!

Translated by