필터 지우기
필터 지우기

Display output in FORTRAN format ?

조회 수: 2 (최근 30일)
Juliette Salexa
Juliette Salexa 2012년 6월 16일
How do I display the numerical contents of an array so that rather than looking like:
A=
5.43297486350203e-005 + 2.66188191742774e-006i
4.93260233930857e-006 + 9.43375107613982e-005i
3.40870376238982e-004 - 5.64562919171371e-003i
it gives something that can be copied and pasted into a FORTRAN code ?
  댓글 수: 1
Juliette Salexa
Juliette Salexa 2012년 6월 17일
I should clarify, that I'm not necessarily trying to write an output file, I'm just trying to display the variable, even if it's just in the Command Window.

댓글을 달려면 로그인하십시오.

답변 (1개)

Walter Roberson
Walter Roberson 2012년 6월 16일
fprintf(fid, '(%f,%f)\n', [real(A(:)), imag(A(:))].' )
  댓글 수: 2
Juliette Salexa
Juliette Salexa 2012년 6월 16일
Thanks Walter.
I was hoping there would be something more like Mathematica's function FortranForm[ ], or Maple's function Fortran( ) ...
Walter Roberson
Walter Roberson 2012년 6월 16일
Nope. But if you want you can create
function s = FortranComplex(V)
s = sprintf( '(%f,%f)', real(V(1)), imag(V(1)) );
and then use the output string in whatever context you want.
If you have the symbolic toolbox, you could try
http://www.mathworks.com/help/toolbox/symbolic/fortran.html
fortran(A) but you might have use fortran(sym(A))

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Fortran with MATLAB에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by