Reputation: 11
I have following code
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)
I want a plot such a that for threshold line of gAll =-22, graph above threshold line should be in red color and graph below threshold line should in blue, but graph should in continuous joint with these two different colors, how to do it.
Upvotes: 0
Views: 62
Reputation: 1587
You can mask areas of the graph by setting values to NaN
. I would create a high resolution interpolant of the data gAll
, then create two coppies, ones with gAll>-22
masked and one with gAll<-22
masked and plot them on the same axes.
You could make gAll_HR
a high resolution version of your vector gAll
on x_HR
with interp1(x, gAll, x_HR)
, then replace values with NaN
using logical indexing:
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-')
Upvotes: 0