Prev: active contour on ultrasound images
Next: separating overlaping field images from n number of images to create panormaic image mosaicing
From: Sebastien on 19 Apr 2010 06:22 I should write data in a specific format for a Fortran software. I know that matlab could read this format, but i don't know how to write in this specific format: 5.D02 matlab return 500 6.25D-02 matlab return 0.0625 My problem is that i want to do the inverse. I want to enter 0.0625 and matlab return 6.25D-02. Is someone could answer me. Regards Sébastien
From: Rune Allnor on 19 Apr 2010 07:24 On 19 apr, 12:22, "Sebastien " <sebastien.yazin...(a)gmail.com> wrote: > I should write data in a specific format for a Fortran software. > I know that matlab could read this format, but i don't know how to write in this specific format: > 5.D02 > matlab return 500 > > 6.25D-02 > matlab return 0.0625 > > My problem is that i want to do the inverse. > > I want to enter 0.0625 and matlab return 6.25D-02. >> x = 0.0625; >> fprintf('%4.2E\n',x); 6.25E-002 >> As for the D or E letter, this is likely a question of locales, and thus depends on the settings on your computer. Rune
From: Doug Schwarz on 19 Apr 2010 08:13 In article <040ad0d5-c4f0-4696-ab83-6c18f4f81888(a)c21g2000yqk.googlegroups.com>, Rune Allnor <allnor(a)tele.ntnu.no> wrote: > On 19 apr, 12:22, "Sebastien " <sebastien.yazin...(a)gmail.com> wrote: > > I should write data in a specific format for a Fortran software. > > I know that matlab could read this format, but i don't know how to write in > > this specific format: > > 5.D02 > > matlab return 500 > > > > 6.25D-02 > > matlab return 0.0625 > > > > My problem is that i want to do the inverse. > > > > I want to enter 0.0625 and matlab return 6.25D-02. > > >> x = 0.0625; > >> fprintf('%4.2E\n',x); > 6.25E-002 > >> > > As for the D or E letter, this is likely a question of locales, > and thus depends on the settings on your computer. > > Rune Doesn't the D mean double precision? I would think both D and E would do the same thing when read by a Fortran program, but as I haven't used Fortran for years I'm not sure. Try both and see. You have another problem in that MATLAB uses standard libraries for the fprintf function and on Windows you get 3 digits for the exponent. So, if you must have 6.25D-02 instead of 6.25E-002 then you have no choice but to use sprintf and then process the text before writing it out to a file (using fprintf and '%s'). -- Doug Schwarz dmschwarz&ieee,org Make obvious changes to get real email address.
From: Sebastien on 19 Apr 2010 08:15 "Sebastien " <sebastien.yazinski(a)gmail.com> wrote in message <hqhasf$3k9$1(a)fred.mathworks.com>... > I should write data in a specific format for a Fortran software. > I know that matlab could read this format, but i don't know how to write in this specific format: > 5.D02 > matlab return 500 > > 6.25D-02 > matlab return 0.0625 > > My problem is that i want to do the inverse. > > I want to enter 0.0625 and matlab return 6.25D-02. > > Is someone could answer me. > > Regards > > Sébastien Thanks a lot for your answer ! Sébastien
From: dpb on 19 Apr 2010 09:42
Doug Schwarz wrote: > In article > <040ad0d5-c4f0-4696-ab83-6c18f4f81888(a)c21g2000yqk.googlegroups.com>, > Rune Allnor <allnor(a)tele.ntnu.no> wrote: > >> On 19 apr, 12:22, "Sebastien " <sebastien.yazin...(a)gmail.com> wrote: >>> I should write data in a specific format for a Fortran software. >>> I know that matlab could read this format, but i don't know how to write in >>> this specific format: >>> 5.D02 >>> matlab return 500 >>> >>> 6.25D-02 >>> matlab return 0.0625 >>> >>> My problem is that i want to do the inverse. >>> >>> I want to enter 0.0625 and matlab return 6.25D-02. >>>> x = 0.0625; >>>> fprintf('%4.2E\n',x); >> 6.25E-002 >> As for the D or E letter, this is likely a question of locales, >> and thus depends on the settings on your computer. >> >> Rune > > > Doesn't the D mean double precision? I would think both D and E would > do the same thing when read by a Fortran program, but as I haven't used > Fortran for years I'm not sure. Try both and see. .... Yes, and yes...the Standard says so on input a D exponent will be interpreted as an E if the input variable is single precision. Where one might need to be careful is if the values being written by OP are not for use as input data records but were for DATA statements, say, to be included in a Fortran program. Fortran promotes single precision to double on assignment but does _not_ extend precision so using an "E" in an internal double precision assignment, for example, ends up w/ the probably unintended result of a single precision value in a double precision variable. -- |