matlab中的Y错误栏

时间:2015-08-10 11:35:44

标签: matlab matlab-figure errorbar

我有30个文件(UE1.dat,UE2.dat,......),它们全部由2列组成(第一列是延迟,第二列是CDF)。因为我没有[100:600]范围内所有延迟的CDF值,我不得不根据所有这30个文件中的第一列插入第二列,然后在0之间标准化数据。 1.到目前为止,一切都很完美。

最后,我必须绘制一个图形,它由x,y和y误差条组成。 x是范围(100:1:600),y是每个x的插值数据的每一行的平均值,从步骤1到100到600,对于y错误条我也计算每个y行的标准偏差。

但是当我用错误条绘制数据时,它看起来很奇怪,我有一些奇怪的x破折号,而如果我只绘制x对抗y,一切看起来都不错。你能给我一些提示如何解决y错误栏的问题,也许我想念一些东西。下面附有MATLAB代码和图表。

clc;
close all;
clear all;
% xq1 = (100:600)
NUM_UES = 30;
NUM_SAMPLES = 501;

for i=1:NUM_UES
%% Loading data
x = load(strcat('C:\Users\tgetsov\Documents\BA THESIS\temp_200\ral\UE',num2str(i),'.cdf.dat'));
y = strcat('C:\Users\tgetsov\Documents\BA THESIS\temp_200\ral\UE',num2str(i),'.cdf.dat');

xq = 100:1:600;
Result(:, i) = interp1(x(:,1), x(:,2), xq, 'linear', 'extrap');
Result_norm(:, i) = (Result(:, i) - min(Result(:, i)))/(max(Result(:, i) - min(Result(:, i))));
end
% p=0:length(Result)-1;
%%Plotting Data
% figure(i);
% % plot(p,Result); hold on;grid;
% plot(xq_i,Result_i);
% hold on;
% grid;
for k=1:NUM_SAMPLES
    avg(k) = mean(Result_norm(k,:));
    min_30_ral(k) = min(Result_norm(k,:),[],2);
    max_30_ral(k)= max(Result_norm(k,:),[],2);
    stdev(k) = std(Result_norm(k,:))*ones(size(xq(:, k)));
    variance(k) = var(Result_norm(k, :));    
end
    v = variance;
    v2 = zeros(size(v));
    v2(1:50:end) = v(1:50:end);
    m = stdev;
    m2 = zeros(size(m));
    m2(1:50:end) = m(1:50:end);
%     [F , X] = ecdf(avg)

figure (1)
% errorbar(xq,avg,min_30_ral,max_30_ral);
% errorbar(xq,avg,m2);
% errorbar(xq,avg,v2);

errorbar(xq,avg,m2);
hold on;
grid;

figure (2)
plot (xq, avg);
hold on;
grid;

x对抗y:

enter image description here

x对y带错误条:

enter image description here

1 个答案:

答案 0 :(得分:0)

要删除错误栏,您可以使用以下Matlab Central问题中 david szotten 提供的答案:http://uk.mathworks.com/matlabcentral/newsreader/view_thread/167875

我将复制并粘贴那里提供的答案:

removeErrorBarEnds.m :
-------------
function removeErrorBarEnds(hErrBar)
%removeErrorBarEnds
% removeErrorBarEnds(hErrBar) removes the lines 
above/below errorbars
% generated by the matlab function hErrBar = errorbar()
%
% Example:
% x = 1:10;
% y = sin(x);
% e = std(y)*ones(size(x));
% h = errorbar(x,y,e)
% oldAx = axis;
% removeErrorBarEnds(h)
% axis(oldAx)

% david szotten

%use length of xdata to find the right handle
%there may be an easier way to do this
dataLen = length( get(hErrBar, 'xdata') );

%objects to try, one of this is the errorbars
candidateList = findall(hErrBar);

for candidate = candidateList(:)'
        candLen = length( get(candidate, 'xdata') );

        %found it
        if candLen == 9 * dataLen
                xOrg = get(candidate, 'xdata');
                yOrg = get(candidate, 'ydata');

                %we only want the first 3 out or every 9
                valuesToExtract = find( kron( ones
(1,dataLen), [ones(1,3) zeros(1,6)]) );
                xNew = xOrg(valuesToExtract);
                yNew = yOrg(valuesToExtract);

                set(candidate, 'xdata', xNew);
                set(candidate, 'ydata', yNew);
        end
end

end

注意:我在这里发布此问题是为了确保知识(和代码)也在STACKOVERFLOW中。