Shade area between two curves

2 次查看(过去 30 天)
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 个)

Image Analyst
Image Analyst 2022-4-3

类别

Help CenterFile Exchange 中查找有关 2-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