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 Kommentare

Rik
Rik am 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 am 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.

Melden Sie sich an, um zu kommentieren.

 Akzeptierte Antwort

Voss
Voss am 2 Apr. 2022

0 Stimmen

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 Kommentar

LIM MING HUI
LIM MING HUI am 3 Apr. 2022
U really help me a lot!!!! Thank you very much!!!!

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Data Distribution Plots finden Sie in Hilfe-Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by