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

9 Ansichten (letzte 30 Tage)
Niklas Kurz
Niklas Kurz am 2 Mai 2021
Beantwortet: Adam Danz am 3 Mai 2021
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 Kommentare
Niklas Kurz
Niklas Kurz am 2 Mai 2021
Bearbeitet: Niklas Kurz am 2 Mai 2021
z = zeros(size(u))
would fullfill the purpose, but the object still is living in 3D
Niklas Kurz
Niklas Kurz am 2 Mai 2021
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.

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Scott MacKenzie
Scott MacKenzie am 2 Mai 2021
Bearbeitet: Scott MacKenzie am 3 Mai 2021
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.

Weitere Antworten (1)

Adam Danz
Adam Danz am 3 Mai 2021
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')

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by