Shade area between two curves

1 view (last 30 days)
LIM MING HUI
LIM MING HUI on 2 Apr 2022
Answered: Image Analyst on 3 Apr 2022
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 Comments
Rik
Rik on 2 Apr 2022
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 on 2 Apr 2022
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.

Sign in to comment.

Accepted Answer

Voss
Voss on 2 Apr 2022
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 Comment
LIM MING HUI
LIM MING HUI on 3 Apr 2022
U really help me a lot!!!! Thank you very much!!!!

Sign in to comment.

More Answers (1)

Image Analyst
Image Analyst on 3 Apr 2022

Categories

Find more on 2-D and 3-D Plots in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!