【问题标题】:plot selected indices in different color using matlab使用 matlab 绘制不同颜色的选定索引
【发布时间】:2015-08-15 19:46:08
【问题描述】:

我正在尝试绘制错误信号。当误差为零时,绘图应为黑色。每当出现错误时,它应该是红色的。我在数组 excdIdx 中捕获有错误的索引。 我的目标是用红色绘制错误索引,用黑色绘制非错误索引。由于某种原因,for 循环不起作用。

ErrAxis 是轴 excdIdx 包含要绘制成红色的索引列表

    h(8) = subplot(plotCount,1,ErrAxis);
    hold off;
    if excdIdx > 0

        plot(time(1:excdIdx),Output(1:excdIdx) - trueSignal(1:excdIdx),'k-'); hold on;

       %this method to plot the error indices in red is not working
       % for elem = 1: size(excdIdx, 2)
       %     index_1 = excdIdx(elem);
       %     index_2 = excdIdx(elem+1);
       %     plot(time(index_1:index_1+1),Output(index_1:index_1+1) - trueSignal(index_1:index_1+1),'r-'); hold on;
       % end 

    else
        plot(time,Output - trueSignal,'k-'); hold on;
    end

【问题讨论】:

  • 能否请您创建一个MCVE

标签: matlab plot colors subplot


【解决方案1】:

如果您要绘制单个数据点,我认为您应该使用scatter。试试下面的代码:

h(8) = subplot(plotCount,1,ErrAxis);
hold off;
if excdIdx > 0
    scatter(time(1:excdIdx),Output(1:excdIdx) - trueSignal(1:excdIdx),'markerfacecolor','k'); hold on;
    for elem = 1: size(excdIdx, 2)
        index_1 = excdIdx(elem);
        index_2 = excdIdx(elem+1);
        scatter(time(index_1:index_1+1),Output(index_1:index_1+1) - trueSignal(index_1:index_1+1),'markerfacecolor','r');
    end
else 
    scatter(time,Output - trueSignal,'markerfacecolor','k'); hold on;
end

【讨论】:

    猜你喜欢
    • 2011-10-10
    • 1970-01-01
    • 2013-05-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-05-15
    • 2012-11-05
    相关资源
    最近更新 更多