# How to show output of a matrix in m(1,1)=a11 m(1,2)=a12 …in this way…i have 50 *50 size matrix

How to show output of a matrix in m(1,1)=a11 m(1,2)=a12 ...in this way......i have 50 *50 size matrix

so i want to do it efficiently.

output to be shown like

m(1,1)=a11 (in fortranForm) m(1,2)=a12 (In fortranform) .... ....continue in this way, one element per one line.

i have specific reason of doing this. i will copy paste my data into Fortran code to use it this data in less time.

• You mean like this !Mathematica graphics Array[a, {5, 5}]? Question not clear. What is the context? ps. I just saw your other question here mathematica.stackexchange.com/questions/65148/… is this different? – Nasser Nov 7 '14 at 19:39
• Hii.....No other question is also same. i just want my matrix output to be shown like this matrix(1,1)=a11 element in fortran form matrix(1,2)=a12 element in fortranform....continue in this way – Amandeep Nov 7 '14 at 20:00

There is no subtlety to this, but it works:

Table[i j, {i, 5}, {j, 5}]
MapIndexed[Print["a(", #2[[1]], "," , #2[[2]], ") = ", #1] &, %, {2}];

• What is %102? – Nasser Nov 7 '14 at 20:51
• @Nasser leftovers my own evaluation. Removed. :P – rcollyer Nov 7 '14 at 20:54
• Ok, now it makes sense :), I thought you were using some new symbol/command in V10 but could not find it. – Nasser Nov 7 '14 at 21:01

building on @rcollyer's answer: The main improvement here is we print the list of elements in a way that the whole list can be copied at once. (also handle arbitrary dimensions automatically )

 SetAttributes[fortranprint, HoldFirst]
fortranprint[array_Symbol] :=
fortranprint[array, SymbolName[Unevaluated[array]]];
fortranprint[array_, name_] :=
Print@StringJoin@Riffle[ Flatten@MapIndexed[ StringJoin@
{"        ", (* leading spaces for fixed format fortran *)
name,
"(", Riffle[ (ToString /@ #2) , "," ], ")=",
ToString[FortranForm[#]]} & , array, {-1}] , "\n"];

b = {{1.432, 2. 10^30}, {0, 1}};
fortranprint[b];

   b(1,1)=1.432
b(1,2)=2.e30
b(2,1)=0
b(2,2)=1

 fortranprint[{{{1, 2}, {3, 4}}, {{5, 6}}}, "g"];

    g(1,1,1)=1
g(1,1,2)=2
g(1,2,1)=3
g(1,2,2)=4
g(2,1,1)=5
g(2,1,2)=6

• Yeah, mine was quick and dirty. I should have done this. +1 – rcollyer Nov 7 '14 at 21:45