2013-10-02 45 views
1

我正在处理来自井的数据,有时工具不会拾取任何信号,并且该间隔将为空= NaN。 我想在此行的区域下遮蔽,但不在没有数据的区域。如何为离散值下的线条阴影区域

例如

: X = [1 2 3楠楠6 7] Y = [5 6 6.5楠楠6〜8]

从数据卸下NaN被不希望的。我尝试使用填充和区域,但不起作用 任何想法?

回答

0

我不知道内在功能的MATLAB的做与南区域的情节,但你可以遍历的“好”的价值观每个部分,并分别绘制他们是这样的:

function testShade() 

x=[1 2 3 NaN NaN 6 7] 
y=[5 6 6.5 NaN NaN 6 8] 

figure(89); 
clf; 
plot(x,y, '-rx', 'linewidth', 3); 
hold on; 
areaWithNaN(x,y); 

function areaWithNaN(x,y) 

badValues = isnan(x); 

while(~isempty(badValues)) 

    ind = find(badValues, 1, 'last'); 

    % if we didn't find anything then plot everything that remains: 
    if isempty(ind) 
     ind = 0; 
    end 

    % If there are multiple bad values in a row then trim them off. This 
    % could be slow and optimized later: 
    if ind == length(badValues) 
     badValues= badValues(1:end-1); 
     continue; 
    end 

    area(x(ind+1:length(badValues)), y(ind+1:length(badValues))); 

    % remove the bad values we no longer care about: 
    badValues= badValues(1:ind-1); 

end 
0

任何插补功能将填补缺失的点。 实施例: 鉴于所述数据集:

x=1:5; 
y=[11 12 NaN 15 30 NaN]; 

创建而不楠的数据集;

x1=x; 
y1=y; 
x1(isnan(y))=[]; 
y1(isnan(x))=[]; 

用插值

yNew=interp1(x1,y1,x); 

这是最简单的插值,用户类型可以在interp1功能的帮助部分找到