Hi everyone,
i want to count the nonzero elements of a row-vector in a loop, i have the initial (360,1000) matrix u_new
for i=1:360; for j=1:1000; if u_new(i,j)==0 %%% here i transformed zeros to Nan, to use the following command isnan
u_new(i,j)=NaN; insample_u_new=isnan(u_new(i,:))==0; %%% in this row-vector the possible values are 0 or 1, i am interested in getting the number of ones
P = numel(insample_u_new(i,j)~= 0); %%%here is the problem
end endend
I want the output P to be the number of the nonzero elements (ones) from the row-vector u_new=u(:,1:1000) for the loop.
Thanks for your answers in advance.
Best Answer