I have a matrix in MATLAB with zeroes and I would like to get another matrix with the first N non-zero elements in each row. Let\'s say for example N = 3<
N
N = 3<
Actually , you can do it like the code blow:
N=3 for n=1:size(A,1) [a b]=find(A(n,:)>0,N); B(n,:)=A(n,transpose(b)); end
Then I think this B matrix will be what you want.