MATLAB线之间的填充区域 [英] MATLAB fill area between lines

查看:755
本文介绍了MATLAB线之间的填充区域的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试做与这篇文章中概述的类似的事情: MATLAB,填写两组数据之间的区域,一个图形中的线 但遇到了障碍.我正在尝试对表示平均值+/-标准偏差的图形区域进行阴影处理.变量的定义有点复杂,但是归结为这段代码,在不加阴影的情况下进行绘制时,我得到以下屏幕截图:

I'm trying to do something similar to what's outlined in this post: MATLAB, Filling in the area between two sets of data, lines in one figure but running into a roadblock. I'm trying to shade the area of a graph that represents the mean +/- standard deviation. The variable definitions are a bit complicated but it boils down to this code, and when plotted without shading, I get the screenshot below:

x = linspace(0, 100, 101)';    
mean = torqueRnormMean(:,1);
meanPlusSTD = torqueRnormMean(:,1) + torqueRnormStd(:,1);
meanMinusSTD = torqueRnormMean(:,1) - torqueRnormStd(:,1);
plot(x, mean, 'k', 'LineWidth', 2)
plot(x, meanPlusSTD, 'k--')
plot(x, meanMinusSTD, 'k--')

但是,当我尝试通过添加下面的代码在图形的下半部分(均值和meanMinusSTD之间)实现阴影时,我得到的图看起来像这样:

But when I try to implement shading just on the lower half of the graph (between mean and meanMinusSTD) by adding the code below, I get a plot that looks like this:

fill( [x fliplr(x)],  [mean fliplr(meanMinusSTD)], 'y', 'LineStyle','--');

显然不是在对图形的正确区域进行阴影处理,并且正在创建新的接近0的水平线,这些线正与阴影打乱.

It's obviously not shading the correct area of the graph, and new near-horizontal lines are being created close to 0 that are messing with the shading.

有什么想法吗?我很困惑.

Any thoughts? I'm stumped.

推荐答案

原来是列与行向量的问题.出于某些原因,将上述fill方法与带原始列向量的flipud一起使用不起作用,但随后使用fliplr转换原始变量即可.去搞清楚.如果有帮助,请参考以下代码:

It turned out to be a column vs row vector issue. For some reason using the fill method above with flipud with the original column vectors doesn't work, but transposing the original variables then using fliplr does. Go figure. Here's the code in case it helps someone else:

x = linspace(0,100, 101);
mean = torqueRnormMean(:,DOF)';
meanPlusSTD = torqueRnormMean(:,DOF)' + torqueRnormStd(:,DOF)';
meanMinusSTD = torqueRnormMean(:,DOF)' - torqueRnormStd(:,DOF)';
fill( [x fliplr(x)],  [meanPlusSTD fliplr(meanMinusSTD)], 'k');
alpha(.25);
plot(x, mean, 'k', 'LineWidth', 2)
plot(x, meanPlusSTD, 'k')
plot(x, meanMinusSTD, 'k')

请注意,我删除了虚线,只是使用细线与粗线来表示标准偏差和均值.我这样做是因为线条样式不一致.这段代码处于一个循环中,其中DOF从1:9开始运行,并且在某些子图中,两个标准曲线都将变为虚线,而在某些曲线中则仅位于顶部或底部.对我来说,让它们破折号并不重要,所以我保持简单.现在,这是我得到的图形的示例:

Note that I removed the dotted line and just used thin vs. thick lines to denote standard deviation and mean. I did this because the line style was inconsistent. This code is in a loop where DOF runs from 1:9, and in some of the subplots both std curves would be dashed and in some just the top or bottom. It didn't matter enough to me to have them dashed so I kept it simple. Now this is an example of the graph I get:

这篇关于MATLAB线之间的填充区域的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆