突出显示 matlab 图的部分 [英] Highlight parts of matlab plot

查看:82
本文介绍了突出显示 matlab 图的部分的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个看起来像这样的 matlab 图:

I have a matlab plot that looks like this:

其中每个子图的 Y 值存储在一维数组中.我想要做的是找到一个区域,其中顶部图形高于某个高度,例如 0.5.我还想在其他图表中突出显示相同的区域.

Where the Y values for each of the subplots are stored in single dimensional arrays. What i would like to do is to find an area where the top graph is above a certain height say 0.5. I would also like to highlight the same area in the other graphs as well.

这是我所谈论的一个例子:

Here is an example of what I am talking about:

到目前为止我能找到的最好的是函数 area,它将填充 matlab 网格上的一个区域.但是,如果有人能告诉我如何使其透明以及如何填充多个区域而无需执行大量区域命令,那就太好了.

The best i have been able to find so far is the function area which will fill an area on the matlab grid. However, if someone could tell me how to make it transparent and also how to fill multiple areas without having to do lots of area commands that would be great.

否则我可以识别结构中的一组区域并使用 for 循环来绘制它们.这是我会这样做的一些伪代码:

Otherwise I can identify a group of areas in a struct and use a for loop to plot them. Here is some psuedo code of the way i would do it:

countstruct = 1;
for i = 1:length(yValue)
    if (yValue(i) > 1)
        outside = [outside, i]
    else
         areas(countstruct).outside = outside;
         countstruct = countstruct + 1;
         clear outside;

     end
 end

然后绘制区域我会这样做:

Then to plot the areas i would do this:

for i = 1:length(areas)
    area(areas(i).outside, ones(length(area), 1)*14, "SomeThingToMakeItTransperant')
end

我会为每个子图执行此操作.显然,这很复杂,所以最好有一个衬里.谁能想到一个?

and i would do this for each of the subplots. Obviously this is quite convoluted so it would be better to have a one liner. Can anyone think of one?

推荐答案

我想通了,我提供的伪代码获得了正确的区域.然后你可以这样做:

I figured it out, The psuedo code i provided gets the correct regions. You can then do this:

for i = 1:length(areas)
    harea = area(areas(i).outside, ones(length(areas(i).outside), 1)*14, 'LineStyle', 'none')
    set(harea, 'FaceColor', 'r')
    alpha(0.25)
    hold on
end

alpha 设置大多数区域图中的透明度.这与问题中的代码相结合导致:

alpha sets the transparency in most area plots. This in combination with the code in the question results in this:

在 matlab 中绘图非常酷.

This is pretty cool to plot in matlab.

这篇关于突出显示 matlab 图的部分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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