MATLAB,填充两组数据之间的区域,一张图中的线 [英] MATLAB, Filling in the area between two sets of data, lines in one figure
问题描述
我有一个关于使用 area
函数的问题;或者也许另一个功能是为了......我从一个大文本文件创建了这个图:
I have a question about using the area
function; or perhaps another function is in order...
I created this plot from a large text file:
绿色和蓝色代表两个不同的文件.我想要做的是分别填充红线和每次运行之间的区域.我可以用类似的想法创建一个面积图,但是当我将它们绘制在同一个图形上时,它们不会正确重叠.本质上,4 个图将在一个图形上.
The green and the blue represent two different files. What I want to do is fill in the area between the red line and each run, respectively. I can create an area plot with a similar idea, but when I plot them on the same figure, they do not overlap correctly. Essentially, 4 plots would be on one figure.
我希望这是有道理的.
推荐答案
根据@gnovice 的答案,您实际上可以仅在两条曲线之间的区域创建带有阴影的填充图.只需将 fill
与 fliplr
.
Building off of @gnovice's answer, you can actually create filled plots with shading only in the area between the two curves. Just use fill
in conjunction with fliplr
.
示例:
x=0:0.01:2*pi; %#initialize x array
y1=sin(x); %#create first curve
y2=sin(x)+.5; %#create second curve
X=[x,fliplr(x)]; %#create continuous x value array for plotting
Y=[y1,fliplr(y2)]; %#create y values for out and then back
fill(X,Y,'b'); %#plot filled area
通过翻转 x 数组并将其与原始数组连接起来,您可以向外、向下、向后、然后向上关闭两个数组,形成一个完整的多面多面体.
By flipping the x array and concatenating it with the original, you're going out, down, back, and then up to close both arrays in a complete, many-many-many-sided polygon.
这篇关于MATLAB,填充两组数据之间的区域,一张图中的线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!