how to convert Fotran format statment in matlab?

조회 수: 5 (최근 30일)
m m
m m 2020년 2월 16일
댓글: James Tursa 2020년 2월 17일
i want to convert this Fortan statment in matlab?
FORMAT(1001E15.6)
  댓글 수: 4
Sindar
Sindar 2020년 2월 16일
Yes, but what does that command do, specifically? I don't know fortran, but I can probably answer the Matlab question from a description
m m
m m 2020년 2월 16일
i don't know im not good in fortran

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

채택된 답변

Walter Roberson
Walter Roberson 2020년 2월 16일
Is the format being used to read data, or to write data?
If it is being used to write data, then the equivalent would be
fmt = repmat('%15.6e', 1, 1001);
It has been a while since I last did any fortran, so I do not recall at the moment if it automatically added newline; you might need to use
fmt = [repmat('%15.6e', 1, 1001), '\n'];
If, on the other hand, it is being used to read data, then there is no direct equivalent. Using '%15.6e' as an input format for fscanf() or sscanf() or textscan() will seldom do what you expect. The easiest way for reading is to use https://www.mathworks.com/help/matlab/ref/matlab.io.text.fixedwidthimportoptions.html
  댓글 수: 1
James Tursa
James Tursa 2020년 2월 17일
"... if it automatically added newline ..."
Yes. On a sequential write to a text file Fortran will add the newline.
Also, note that in Fortran the format 15.6e on input typically just has the effect that a floating point number will be read in 15 characters. The actual format of the number in those 15 characters will override the 15.6e specific format of the read statement. I.e., the actual number in those 15 characters doesn't have to have exactly 6 decimal values listed after the decimal point, and it doesn't have to have an exponent listed. Pretty much any valid floating point syntax that fits in 15 characters on input will work.

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

추가 답변 (0개)

카테고리

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