问题描述
我有一个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图的一部分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!