Filter löschen
Filter löschen

What is the best way to fill the areas between lines in a graph with logarithmic axis?

6 Ansichten (letzte 30 Tage)
Hello!
Would someone be so kind as to help me in my attempt to fill the area between two curves?
The x-axis must be logarithmic! Unfortunately, I don't know where my mistake lies and would be grateful for help.
Workable code is below.
Thanks and greetings
faktorOG = [1.45 1.2 1.2 1.2 1.2 1.2 1.2 1.2];
faktorUG = [0.65 0.8 0.8 0.8 0.8 0.65 0.6 0.5];
Frequenzen = [125 250 500 1000 2000 4000 5000 8000];
x = Frequenzen;
% Figure Toleranzbereich Ober- und Unter Grenze
figure
grid on
hold on
semilogx(x,faktorOG, 'k-',...
x,faktorUG, 'k:','LineWidth',1.5)
inBetweenRegionX = [1:length(faktorUG), length(faktorOG):-1:1];
inBetweenRegionY = [faktorUG, fliplr(faktorOG)];
% Display the area first so it will be in the background.
fill(inBetweenRegionX, inBetweenRegionY, 'g');
xticks([125 250 500 1000 2000 4000 10000])
xticklabels({'125','250','500','1000','2000','4000','10000'})
legend('Obergrenze','Untergrenze')

Antworten (1)

Sandeep Mishra
Sandeep Mishra am 14 Jun. 2023
Hello Stefan,
I understood that you are trying to plot two graphs "faktorOG" and "faktorUG" on the semilog axis "Frequenzen" and want to fill the area between these two plots.
In MATLAB, the "fill" function provides you the functionality to plot filled polygonal regions as patches with vertices at the (x,y) locations specified by X and Y
You can implement the fill function like below.
% Coloring the area between two plots using "flip"
fill([x fliplr(x)], [faktorOG fliplr(faktorUG)], 'r');
You can refer to the below documentation to learn more about "fill" in MATLAB

Kategorien

Mehr zu 2-D and 3-D Plots finden Sie in Help Center und File Exchange

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by