Hello,
I have two PSD graphs and I want to fill the area between them.
I used this code but it didn't work properly:
figure(3)
x2 = [f2(321:1921,:), fliplr(f2(321:1921,:))];
inBetween = [yconf(321:1921,1), fliplr(yconf(321:1921,2))];
fill(x2, inBetween, 'g');
Does anyone know how I can fix it?
Thanks,
Amir

 Akzeptierte Antwort

Voss
Voss am 16 Mär. 2022
Bearbeitet: Voss am 16 Mär. 2022

1 Stimme

You should use flipud() or flip(_,1) or just use indexing (and do vertical concatenation with ; rather than horizontal concatenation with ,):
% some data similar to yours for the purpose of filling between:
f2 = linspace(0,30,64*30+1).';
yconf = -40*sin(f2)-40+[0 -20];
plot(f2,yconf);
xlim([5 30]);
% fill using flip():
figure()
x2 = [f2(321:1921,:); flip(f2(321:1921,:),1)];
inBetween = [yconf(321:1921,1); flip(yconf(321:1921,2),1)];
fill(x2, inBetween, 'g');
xlim([5 30]);
% fill using indexing:
figure()
x2 = f2([321:1921 1921:-1:321],:);
inBetween = [yconf(321:1921,1); yconf(1921:-1:321,2)];
fill(x2, inBetween, 'g');
xlim([5 30]);

4 Kommentare

Amir Hosein Shokouhy
Amir Hosein Shokouhy am 16 Mär. 2022
Awesome, thanks. Is there anyway I could remove the black line borders?
You're welcome!
Specify 'EdgeColor','none' in the call to fill() to draw no border around the patch object. Here it is on top of the lines it is based on:
% some data similar to yours for the purpose of filling between:
f2 = linspace(0,30,64*30+1).';
yconf = -40*sin(f2)-40+[0 -20];
plot(f2,yconf);
xlim([5 30]);
hold on
% fill using indexing:
x2 = f2([321:1921 1921:-1:321],:);
inBetween = [yconf(321:1921,1); yconf(1921:-1:321,2)];
fill(x2, inBetween, 'g', 'EdgeColor','none');
xlim([5 30]);
Amir Hosein Shokouhy
Amir Hosein Shokouhy am 16 Mär. 2022
Thank you very much!
Voss
Voss am 17 Mär. 2022
You're welcome!

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

Davide Masiello
Davide Masiello am 16 Mär. 2022
Bearbeitet: Davide Masiello am 16 Mär. 2022

0 Stimmen

I think the problem might be that your y-values are column vectors, and therefore you create a matrix when you concatenate them using the comma.
Maybe this will work
figure(3)
x2 = [f2(321:1921,:), fliplr(f2(321:1921,:))];
inBetween = [yconf(321:1921,1)', fliplr(yconf(321:1921,2))'];
fill(x2, inBetween, 'g');

Kategorien

Mehr zu Graphics Object Properties finden Sie in Hilfe-Center und File Exchange

Gefragt:

am 16 Mär. 2022

Kommentiert:

am 17 Mär. 2022

Community Treasure Hunt

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

Start Hunting!

Translated by