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

조회 수: 25 (최근 30일)
Niklas Kurz
Niklas Kurz 2021년 5월 2일
답변: Adam Danz 2021년 5월 3일
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