Hello, how could I fill a figure bounded by a curve?

1 回表示 (過去 30 日間)
Andrea Astarita
Andrea Astarita 2017 年 2 月 14 日
コメント済み: Jake Simmonds 2019 年 2 月 1 日
I have a quite complex plot and I would like to fill with colour the bounded areas I am trying to use area(x,y) function but it doesn't work... This is my script
if true
% code
figure()
hold on
for i=1:(2*n)
x=zeros(1,length(phi));
y=x;
r=x;
r=r_phi0(i)*exp(b*phi);
x=r.*cos(phi);
y=r.*sin(phi);
plot(x,y)
if (i>1 && mod(i,2)==0)
drawLine([r_phi0(i-1) 0],[r_phi0(i) 0]);
if mod(N,2)==0
drawLine([r_phiN(i-1) 0],[r_phiN(i) 0]);
else
drawLine([-r_phiN(i-1) 0],[-r_phiN(i) 0]);
end
end
area(x,y)
axis tight
end
end
This is what it plot without using area()...
thank you all.

採用された回答

Easwar Kumar Yarrabikki
Easwar Kumar Yarrabikki 2017 年 2 月 14 日
Hello Astarita,
You can use fill function in MATLAB. All you just need is X and Y axis data for both curves. I also wrote sample code you can play with your data.
fill([X data for line1',fliplr(X data for line 2')]',[(Y data for line 1', ... fliplr((Y data for line 2)')]','required color');
  1 件のコメント
Jake Simmonds
Jake Simmonds 2019 年 2 月 1 日
Wish this code would work for my situation :(

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

その他の回答 (0 件)

カテゴリ

Help Center および File Exchange2-D and 3-D Plots についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by