# Output of matrix in FortranForm

matr2 = Table[FortranForm[matr[[i, j]]], {i, 4}, {j, 6}]


but i want output to be more like this

matrix(1,1)=a11 output in Fortranform

matrix(1,2)=a12 output in Fortranform

matrix(1,3)= same way

that is i want elements to be assigned to some matrix variable and output to be shown in line by line (one element in one line).

output to be shown like matrix(1,1)= output in fortranform

because i want to use output in Fortran code, so i want to display output with matrix variable so that i can copy paste data from here and use matrix variable in fortran code. so please any help regarding this.

• Welcome to Mathematica.SE! I suggest the following: 1) As you receive help, try to give it too, by answering questions in your area of expertise. 2) Read the faq! 3) When you see good questions and answers, vote them up by clicking the gray triangles, because the credibility of the system is based on the reputation gained by users sharing their knowledge. Also, please remember to accept the answer, if any, that solves your problem, by clicking the checkmark sign! – user9660 Nov 7 '14 at 18:40

You could also use Export to export to a file directly. Or use CopyToClipboard :

matr = RandomReal[{10^-12, 10^-6}, {4, 6}];
matr2 = Table[FortranForm[matr[[i, j]]], {i, 4}, {j, 6}];
matr3 = ExportString[
Flatten@Table[
"matrix(" <> ToString[i] <> "," <> ToString[j] <> ") = " <>
ToString[matr2[[i, j]]], {i, Length[matr2]}, {j,
Length[matr2[]]}], "Table"]
CopyToClipboard[matr3]

• i have matrix and i have shown the output in fortranForm. but due to large characters in elements of matrix, when i copied the data into fortran Code, it does not take copied data because of line exceeding characters 2048. so i have to put "& operator" operator in Fortran Form output.....how to do that? please help – Amandeep Nov 8 '14 at 12:19
• feyncalc.org/FeynCalcBook/Write2 – Rolf Mertig Nov 8 '14 at 20:20

Change rows and columns to taste.

rows = 2;
columns = 3;

matr = RandomReal[{10^-12, 10^-6},
{rows, columns}];

(matr2 = Table[Row[{
"matrix(", i, ",", j, ") = ", FortranForm[matr[[i, j]]]}],
{i, Length[matr]},
{j, Length[matr[]]}] //
Flatten) // Column • in The above output, suppose matrix(1,1)=output is very long characters. so in Fortrancode there is need of continuation character in that output after specified no. of characters. this difficulty how to overcome?? please help – Amandeep Nov 9 '14 at 11:16
• You've posted this question at mathematica.stackexchange.com/questions/65207/… Look for answers there. – Bob Hanlon Nov 9 '14 at 14:07