MATLAB: Convert a matrix with some zero to non zero txt file matrix for example I have this matrix: [ 1 2 3 ; 1 0 0 ; 0 0 0; 4 5 6] I want to save it to a txt file: 1 2 3 1 4 5 6 (also delete zero rows completely.) Best Answer a=[ 1 2 3 ; 1 0 0 ; 0 0 0; 4 5 6] Ifor k=1:size(a,1) b=a(k,:) b=b(b~=0); dlmwrite('file1.txt',b,'-append')end Related SolutionsMATLAB: How to insert rows and colums of zeroes in this matrix ??? a=[1 2 3;4 5 6] Here is one quick way to interlace columns and rows of zeros:>> a=[1 2 3;4 5 6];>> b = zeros(2*size(a));>> b(1:2:end,1:2:end) = ab = 1 0 2 0 3 0 0 0 0 0 0 0 4 0 5 0 6 0 0 0 0 0 0 0 MATLAB: Adding zeros to an array OutPut = B;OutPut(3,4) = 0; Related QuestionConvert a matrix with some zero to non zero matrixCombining matrices by replacing zerosWhere is the zero
Best Answer