MATLAB: Exclude values of a matrix inside a for loop

arrayerrorfor loopmatrix

Hello
what should I include in my for loop so that it can ignore some data in my matrixes?
my code is like:
xler=cumsum([1/3 1/3 1/3 0.5 0.5 0.5 0.5 0.5 0.5 1 1 2 1.27])*D;
z=zeros(8,13);
k=zeros(8,13);
K=zeros(1,13);
K_ave=zeros(1,13);
for n=1:13
z(:,n)=results(results(:,1)==xler(n),3);
k(:,n)=results(results(:,1)==xler(n),10);
K(:,n)=sum((k(2:end,n)+k(1:end-1,n))./2.*(z(2:end,n)-z(1:end-1,n)));
K_ave(n)=K(:,n)./max(z(:,n));
end
some arrays are outliers and I dont want to use them in my calculations; outliers are: z(1,13) and k(1,13)
when I include
z(1,13)=[];
k(1,13)=[];
in my codes it gives the error:
A null assignment can have only one non-colon index.

Best Answer

you can replace the outliers by NaN before the loop and then use nanmax and nansum in your calculations