A matrix with both non-zero and zero elements is given. I want to print only the non-zero elements of the matrix. What is syntax that have to be used for this?
matr2 = Table[FortranForm[matrixx[[i, j]]], {i, 12}, {j, 12}]; matr3 = ExportString[ Flatten@Table[ "matrix(" <> ToString[i] <> "," <> ToString[j] <> ") = " <> ToString[matr2[[i, j]]], {i, Length[matr2]}, {j, Length[matr2[[1]]]}], "Table"] CopyToClipboard[matr3]
This commnand prints the data of matrix matr2 as matrix(1,1)=a11 element of matr2. So my question is related to this that is if i want to print only the non-zero elements of matr2? what syntax should i have to added in this?
DeleteCases[#, 0] & /@ mat
. $\endgroup$