3D surface issues HELP!

1 回表示 (過去 30 日間)
James
James 2014 年 10 月 7 日
コメント済み: James 2014 年 10 月 7 日
  • * So these are the questions... most of the variables are fixed the long equation has been dramatically simplified in my code :) * *
  • | This is what mine looks like.. |
What it should look like...
This is my code...
% Q = theta
r = linspace(0,15,200);
Q = linspace(0,2*pi,200);
[r,Q] = meshgrid(r,Q);
w = 14.0591*(1-(r/15)^2)^2 + 15;
x = r.*cos(Q);
y = r.*sin(Q);
mesh(x,y,w)
What have I done wrong? Why isnt mine round, I dont think 'r' is being inputed into the 'w' equation correctly, HELP!

採用された回答

Star Strider
Star Strider 2014 年 10 月 7 日
You need to vectorise your code and it will do just what you want:
r = linspace(0,15);
Q = linspace(0,2*pi);
[r,Q] = meshgrid(r,Q);
w = 14.0591*(1-(r/15).^2).^2 + 15;
x = r.*cos(Q);
y = r.*sin(Q);
mesh(x,y,w)
  9 件のコメント
Star Strider
Star Strider 2014 年 10 月 7 日
編集済み: Star Strider 2014 年 10 月 7 日
My pleasure!
The sincerest expression of gratitude here on MATLAB Answers is to Accept the answer that most closely solves your problem.
James
James 2014 年 10 月 7 日

サインインしてコメントする。

その他の回答 (1 件)

Image Analyst
Image Analyst 2014 年 10 月 7 日
r is an array so you need .^ and not just ^. Try this:
workspace;
r = linspace(0,15,200);
Q = linspace(0,2*pi,200);
[r,Q] = meshgrid(r,Q);
w = 14.0591*(1-(r/15).^2).^2 + 15;
x = r.*cos(Q);
y = r.*sin(Q);
mesh(x,y,w)
% Enlarge figure to full screen.
set(gcf, 'Units', 'Normalized', 'OuterPosition', [0 0 1 1]);
  1 件のコメント
James
James 2014 年 10 月 7 日
編集済み: James 2014 年 10 月 7 日
Thank you so much!
I have a few more questions: ALL GOOD NOW :)
  • I want it to be a surface plot, i did surfc(x,y,w) but i want specifically 10 countours, how do i make this happen?
  • And it is very black :S i want a nice range of colours, this is when i do a surface plot
(Both answers were fantastic, this is the same reply to the previous answer, feel free to help out some more :) )

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeSurface and Mesh Plots についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by