我需要做的是编写代码来计算在一个非常大的文本文件中找到的数值数据的最小值,最大值,平均值和标准值,我已经完成了 . 但是,我还需要绘制数据的2D直方图,这是我遇到麻烦的地方 . 数据不包含负数(虽然在某些时候我需要知道如何处理那个!)并且包含NaN,并且直方图将需要使用1000个二进制位来平滑数组中的49,000个值 . 因此,x轴是bin,y轴是数组中值的数量分布 . 这就是我所拥有的:

N = 100; %I'm using blocks because it's so much data
solarmax = fopen('ACE_magswe_64sec_2000.txt','r+');
formatSpec = '%*d %*d %*d %*d %*f %f %f %f %f %f %f %f %f';

minNp = []; %These are to store the data
maxNp = [];
meanNp = [];
stdNp = [];

minTp = [];     %Above(formatSpec) I'm ignoring the first few columns I don't need 
maxTp = [];  %Below(HeaderL) I'm ignoring the first 2 rows of string data I don't need
meanTp = [];
stdTp = [];


while ~feof(solarmax)
    C = textscan(solarmax,formatSpec,N,'HeaderLines',2,'Delimiter','\t'); 
    Np = cell2mat(C(:,1)); %Calling the columns of data I need
    Tp = cell2mat(C(:,2));

    Np(Np == -9999.90039) = NaN; %Replacing default error values chosen by satellite
    Tp(Tp == -9999.90039) = NaN;

    minNp(end+1) = min(Np);
    maxNp(end+1) = max(Np);
    meanNp(end+1) = mean(Np);
    stdNp(end+1) = std(Np);

    minTp(end+1) = min(Tp);
    maxTp(end+1) = max(Tp);
    meanTp(end+1) = mean(Tp);
    stdTp(end+1) = std(Tp);

end
fclose(solarmax);

nanmin(minNp);      %nan command ignores NaNs in computation
nanmax(maxNp);      %not sure why it didn't do that anyway but whatever
nanmean(meanNp);
nanstd(stdNp);
nanmin(minTp);      %These are here to compute the same operation on the 
nanmax(maxTp);      %blocks of data & so I can check that it's working properly
nanmean(meanTp);
nanstd(stdTp);

所以,我尝试在while循环中包含hist命令,就像我做其他函数一样,但它只是一个不同的动物,相信我,我看了,我发现了很多关于直方图的信息,但没有像我的情况 . 我是否将它包含在while循环中?数据已定义,但它的阅读和存储必须不同......请帮助我...谢谢您的时间

UPDATE

我决定暂时尝试单独绘制直方图而不用其他乱七八糟 .

N = 150;
solarmax = fopen('ACE_magswe_64sec_2000.txt','r+');
formatSpec = '%*d %*d %*d %*d %*f %f %f %f %f %f %f %f %f';

histcNp = []; %I need somewhere to store the data in the blocks but I'm wondering
histcTp = []; %if it already does that in bincounts

while ~feof(solarmax)
    C = textscan(solarmax,formatSpec,N,'HeaderLines',2,'Delimiter','\t');
    Np = cell2mat(C(:,1)); %my data should be defined here
    Tp = cell2mat(C(:,2));

    Np(Np == -9999.90039) = NaN;
    Tp(Tp == -9999.90039) = NaN;

    binranges = 0:150;

    %NpH = histcNp(end+1); %as you can see I've tried stuff and then commented
    %TpH = histcTp(end+1); %it so I can go back

    %histcNp = (Np,0:150);
    %histcTp = (Tp,0:150);



 end
fclose(solarmax);

%bar(Np,0:494110,'histc');
%bar(NpH,Name,density);
%bar(Tp,0:494110,'histc');
bar(0:150,Np,'histc');
[bincounts] = histc(Np,binranges);

就这样我似乎没有太过混乱 . 我的直接问题是我是否定义了循环外的箱数?感谢您的时间 .