0
$\begingroup$
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.

$\endgroup$
  • $\begingroup$ 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! $\endgroup$ – user9660 Nov 7 '14 at 18:40
1
$\begingroup$

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[[1]]]}], "Table"]
CopyToClipboard[matr3]
$\endgroup$
  • $\begingroup$ 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 $\endgroup$ – Amandeep Nov 8 '14 at 12:19
  • 1
    $\begingroup$ feyncalc.org/FeynCalcBook/Write2 $\endgroup$ – Rolf Mertig Nov 8 '14 at 20:20
2
$\begingroup$

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[[1]]]}] //
    Flatten) // Column

enter image description here

$\endgroup$
  • $\begingroup$ 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 $\endgroup$ – Amandeep Nov 9 '14 at 11:16
  • $\begingroup$ You've posted this question at mathematica.stackexchange.com/questions/65207/… Look for answers there. $\endgroup$ – Bob Hanlon Nov 9 '14 at 14:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.