以另一种颜色绘制来自矩阵的序列中的特定值

Plot specific values coming in a sequence from a matrix in a another color

我正在绘制我的 matrix <1x10000>,其中包含以下值:

30, 30, 30, 60, 60, 60, 25, 25, 25, 25, 70, 70, 70, 10, 10, 10 and so on...

这给了我一条我想要的水平线。现在我想 select 另一种颜色或添加标签或任何你觉得方便的地方,在为值 60, 25, 70 绘制线的地方(它们有多少并不重要,但它们必须按顺序出现).

示例:

我们有一个从矩阵绘制的图表。矩阵由这些值组成:

myMatrix = [30, 30, 30, 60, 60, 60, 25, 25, 25, 25, 70, 70, 70, 10, 10, 10]

这给出了一条蓝线 plot(myMatrix, 'b')
现在我想用另一种颜色绘制 60、25、70 的整个序列,或者有某种标签显示:“这里是 60, 25, 70 的序列。所以,30, 30, 30 会在蓝色,60, 60, 60, 25, 25, 25, 25, 70, 70, 70 将是另一种颜色或在该行旁边有一个标签,然后 10, 10, 10 将是蓝色。

需要指出的重要一点是,这些值必须完全符合 sequence/copy,换句话说,60, 25, 70 适用于:

60, 60, 60, 25, 25, 70, 70, 70

但是

60, 60, 60, 80, 70, 70

不会染成蓝色以外的其他颜色。

如果解释是"a bit how ya doin!",我们深表歉意。全新的 Matlab。

这是查找和绘图的代码:

myMatrix = [30, 30, 30, 60, 60, 60, 25, 25, 25, 25, 70, 70, 70, 10, 10, 10];
d = diff([myMatrix(1) myMatrix]); % find all switches between diferent elements
len = 1:numel(myMatrix); % make a list of all indices in myMatrix
idx = [len(d~=0)-1 numel(myMatrix)]; % the index of the end each group
counts = [idx(1) diff(idx)]; % the number of elements in the group
elements = myMatrix(idx); % the type of element
n_groups = numel(idx); % the no. of groups in the vector

values = [60 25 70];
mask = zeros(1,numel(myMatrix));
for k = 1:n_groups-numel(values)+1
    if isequal(values,elements(k:k+numel(values)-1))
        if k>1
            mask(idx(k-1)+1:idx(k+numel(values)-1)) = 1;
        else
            mask(1:idx(k+numel(values)-1)) = 1;
        end
    end
end
imagesc(mask)
colormap([0 0 1;0 1 0])
axis image
axis off

给出:

以及:

myMatrix = [1 2 3 2 1 2 1 2 3 2 1 3 2 3 2 1 2 3 2 1 2 3 2 1 2 3];
values = [1 2 3];

我们得到: