Shade area between two curves

2 ビュー (過去 30 日間)
LIM MING HUI
LIM MING HUI 2022 年 4 月 2 日
回答済み: Image Analyst 2022 年 4 月 3 日
Hello,
I'm trying to fill the area between these two curves:
I had tried to use fill and patch function to shade but I didnt make it...
Any idea on how to fix the problem?
Thank you in advance for your help!
To get my first pic, please follow my step...
  1. Open 'combinefyp.slx'.
  2. Go to matlab and type the following variable.
ve = 25;
la = 4.6;
lx = 26.1;
yl = 3.7;
le = 4.6;
g = 9.8;
miu = 0.5;
3. Back to simulink then click 'Run'.
4. Go to matlab and type the following command.
plot(out.va1,out.L1);
hold on;
plot(out.va2,out.L2);
hold on;
  2 件のコメント
Rik
Rik 2022 年 4 月 2 日
Can you show what syntax you tried for the call to patch? And can you attach the out variable in a mat file?
LIM MING HUI
LIM MING HUI 2022 年 4 月 2 日
patch([out.va1, fliplr(out.va1)],[out.L1,fliplr(out.L2)],'r')
X=[out.va1,fliplr(out.va1)];
Y=[out.L1,fliplr(out.L2)];
fill(X,Y,'b');
-out.va1 and out.va2 are the same variables which is 25 to 50.

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

採用された回答

Voss
Voss 2022 年 4 月 2 日
My best guess for what's happening (since I don't have your variables and I don't have Simulink) is that the variables are column vectors, so that fliplr and horizontal concatenation is not an appropriate mathod for using the variables for patch vertices.
First, I try to reproduce the problem:
% I don't have Simulink, so I make a struct
% 'out' similar to yours (my best guess):
out = struct( ...
'va1',(25:50).', ...
'va2',(25:50).', ...
'L1',linspace(-5,25,26).', ...
'L2',0.1*(25:50).'.^2-3*(25:50).'+16.6);
% plot the lines the same way you do:
plot(out.va1,out.L1);
hold on;
plot(out.va2,out.L2);
% create the patches like you do:
patch([out.va1, fliplr(out.va1)],[out.L1,fliplr(out.L2)],'r');
X=[out.va1,fliplr(out.va1)];
Y=[out.L1,fliplr(out.L2)];
fill(X,Y,'b');
Now, I try to fix the problem (if my guess is correct):
figure();
% plot the lines the same way:
plot(out.va1,out.L1);
hold on;
plot(out.va2,out.L2);
% create a patch using flipud and vertical concatentation:
patch([out.va1; flipud(out.va1)],[out.L1; flipud(out.L2)],'b');
  1 件のコメント
LIM MING HUI
LIM MING HUI 2022 年 4 月 3 日
U really help me a lot!!!! Thank you very much!!!!

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

その他の回答 (1 件)

Image Analyst
Image Analyst 2022 年 4 月 3 日

カテゴリ

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