Matlab 如何使用离散值对线下的区域进行着色
我正在处理来自油井的数据,有时工具不会拾取任何信号,并且该间隔将为空=NaN。 我想在这条线的区域下着色,但不想在没有数据的部分中着色 例如: x=[1 2 3楠楠6 7] y=[5 6.5楠楠6 8] 不需要从数据中删除NaN。我试着使用填充和面积,但不起作用Matlab 如何使用离散值对线下的区域进行着色,matlab,Matlab,我正在处理来自油井的数据,有时工具不会拾取任何信号,并且该间隔将为空=NaN。 我想在这条线的区域下着色,但不想在没有数据的部分中着色 例如: x=[1 2 3楠楠6 7] y=[5 6.5楠楠6 8] 不需要从数据中删除NaN。我试着使用填充和面积,但不起作用 有什么想法吗?我不知道用NaN绘制面积图的内在MATLAB函数,但你可以迭代“好”值的每一部分,然后像这样分别绘制它们: function testShade() x=[1 2 3 NaN NaN 6 7] y=[5 6 6.5 Na
有什么想法吗?我不知道用NaN绘制面积图的内在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
任何插值函数都将填充缺失的点。 例子: 鉴于数据集:
x=1:5;
y=[11 12 NaN 15 30 NaN];
创建一个没有Nan的数据集
x1=x;
y1=y;
x1(isnan(y))=[];
y1(isnan(x))=[];
使用插值
yNew=interp1(x1,y1,x);
这是最简单的插值,用户类型可以在函数的帮助部分找到