Problem with fill()/patch() between two lines in R2023a
8 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Lorenzo Tortora
il 2 Nov 2023
Commentato: Star Strider
il 2 Nov 2023
I have a problem with the fill()/patch() command when plotting experimental data.
I want to plot a sine wave with an atan background, and i want to make a picture in which the filled region is the one between the two waves. However, when i attempt to fill() (or patch()) i get a straigth line going from the first to the last point in the functions i create, and i don't know how to avoid this.
What am i doing wrong?
Here is the code for the plot:
%define the variable
x = 0:0.05:6.28
x = transpose(x)
bg = atan(-x)
linetofill = sin(x)
bg
%plot raw spectrum
plot(x, linetofill)
hold on
%fill the lines up to the background contribution
fill([x fliplr(x)], [linetofill fliplr(bg)], 'cyan', "FaceAlpha", 0.5)
hold off
1 Commento
Risposta accettata
Star Strider
il 2 Nov 2023
I am not certain what result you want.
For column vectors, use flip (or flipud) and concatenate the vector arguments vertically —
%define the variable
x = 0:0.05:6.28;
x = transpose(x);
bg = atan(-x);
linetofill = sin(x);
% bg
%plot raw spectrum
plot(x, linetofill)
hold on
%fill the lines up to the background contribution
patch([x; flip(x)], [linetofill; flip(bg)], 'cyan', "FaceAlpha", 0.5)
hold off
Is this what you want? (The fill function produces the same result. Use the function you are most comfortable wiith.)
.
2 Commenti
Più risposte (0)
Vedere anche
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

