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
与
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屋!