如何在matlab中绘制这个?

时间:2016-05-18 13:54:29

标签: matlab plot matlab-figure figure

我有以下代码

xr=randi([1 150],1,20)
    z=numel(xr);
    N=10;  %Window length
    gAll=zeros(1,z-N+1);
    for n=0:z-N;
        x=xr(1+n:N+n)
      d=max(x);
        m=numel(x);
        y=zeros(d,1);
        p=zeros(d,d);
        for k=1:m-1
        y(x(k))=y(x(k))+1; 
        p(x(k),x(k+1))=p(x(k),x(k+1))+1;
        end
        p=bsxfun(@rdivide,p,y);
        p(isnan(p)) = 0; 
        j=prod(p(p~=0));
        [~,~,idx] = unique(x);
        q=prod(hist(idx,1:max(idx))/numel(x));
        s=log(j);
        l=log(q);
        g=s+l
    gAll(n+1)=g;
    end
    plot(gAll)

我想要一个这样的图,对于gAll = -22的阈值线,上面的阈值线图应该是红色,而低于阈值线的图应该是蓝色,但图应该与这两种不同的颜色连续联合,如何这样做。

1 个答案:

答案 0 :(得分:0)

您可以通过将值设置为NaN来屏蔽图表的区域。我将创建一个数据gAll的高分辨率插值,然后创建两个coppies,其中gAll>-22蒙版和一个gAll<-22蒙版,并将它们绘制在相同的轴上。

您可以使用gAll_HRgAll x_HRinterp1(x, gAll, x_HR)制作NaN高分辨率版本,然后使用逻辑索引将值替换为gAll_low = gAll_HR; gAll_low(gAll_HR>=-22) = NaN; gAll_high = gAll_HR; gAll_high(gAll_HR<-22) = NaN; plot(x_HR, gAll_low, 'b-', x_HR, gAll_high, 'r-') :< / p>

var express = require('express')
    , path = require('path')
    , fs = require('fs')
    , bodyParser = require('body-parser')
    , morgan = require('morgan');

var apps = express();
var staticRoot = __dirname + '/';
apps.set('port', (process.env.PORT || 3000));
apps.use(express.static(staticRoot));
apps.use(bodyParser.urlencoded({ extended: false }));
apps.use(bodyParser.json());
apps.use(morgan('dev'));

apps.use(function (req, res, next) {

    var ext = path.extname(req.path);
    if (ext !== '') {
        return next();
    }
});



apps.get('/getTpl', function (req, res) {

    res.writeHead(200);
    res.end(JSON.parse(["tp1", "tp2", "tp3", "tp4", "tp5", "tp6", "tp7"]));

});

apps.listen(apps.get('port'), function () {
    console.log('serveur en route, port : ', apps.get('port'));
});