我有一个数组A(我写的是为了使它类似于我正在使用的矩阵):
%%%%%%%%%%%%%这是Matrix %%%%%%%%%%%%%%%%%%%%%<<
a = 3; b = 240; c = 10; d = 30; e = 1;
mtx1 = a.*rand(30,1) + a;
mtx2 = round((b-c).*rand(30,1));
mtx3 = round((d-e).*rand(30,1));
mtx4 = -9999.*ones(30,1);
A = [mtx1 mtx2 mtx3 mtx4];
for i = 10:12
for ii = 17 :19
A(i,:)= -9999;
A(ii,:)= 999;
end
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %
我会计算一些统计值,从计算中排除** - 9999 和 999 。
必须针对每列计算统计值。 列分别代表:风速,方向和 其他参数
我写了一段代码但不正确
[nr,ncc]=size(A);
for i=1:ncc
B = A(:,i); %// Temp Vector
Oup=1; Odw=1; %// for Vector Control
while Oup>0 %// || Odw>0 % Oup>0 OR Odw>0 , Oup>0 && (AND) Odw>0
B=sort(B,'descend');
U = find(B<999 & B>-9999); % find for each column of the temp
%vector
Oup = length(U); % Calculates the length
B(U)=[]; % Delete values -9999 and 9999
end
% calculates parameters with the vector temp
count(i)=length(B);
med(i)=mean(B);
devst(i)=std(B);
mediana(i)=median(B);
vari(i)=var(B);
kurt(i)=kurtosis(B);
Asimm(i)=skewness(B);
Interv(i)=range(B);
Mass(i)=max(B);
Mini(i)=min(B);
if length(B)<nr
B(length(B)+1:nr)=nan;
end
C(:,i)=B(:); %//reconstruction of the original matrix
end
你会有什么建议吗?
答案 0 :(得分:1)
如果您的数据集位于A
,并且您希望使用函数f
对其进行操作,则只需使用逻辑索引,即:
f(A( ~(A==999 & A==-9999) )) =...
或者,使用find
和线性索引:
ind = find( ~(A==999 & A==-9999) );
f(A(ind)) = ....