Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

To resolve issues starting MATLAB on Mac OS X 10.10 (Yosemite) visit: http://www.mathworks.com/matlabcentral/answers/159016

How to write a big file

Asked by ita on 12 Jul 2013

I need to write a .dat file to be read by a program. The problem is that this .dat has 2700 lines and I can not write fprint for each line. Here is an extract of the program:

     CASO TESTE  LE e LDireito                                                   
<  MACH  ><  ALPHA >[  BETA  ]<   RE   ><  CAX   ><   SW   >                    
   0.840    0.30000     0.     33000000.   3.194    72.7200                     
[   ICL  ][   CL   ][  DCLDA ]                                                  
   0.        .45      .10                                                       
[  PSE   ][ DELWING][  IBEAM ][  IAIL  ][  IROT  ][  IBLF  ]                    
    1.        0.        0.        0.        0.         0.                       
[  PA1   ]                                                                      
   0.70                                                                         
[  PA2   ]                                                                      
   .77          

Some of these numbers are not variable, so they can be written, but some are variables and must be %10f.

What can I do?

Thank you

1 Comment

Matt Kindig on 12 Jul 2013

Why can't you write fprintf for each line? How are the various fields (<MACH>, < DELWING>, etc.) determined? In what form is your current data?

ita

Products

No products are associated with this question.

1 Answer

Answer by per isakson on 12 Jul 2013

2700 rows of text should be no problem to write with fprintf and a loop. The resulting file will be a couple of MB at most. There is no better way.

You need to be more specific on the reason to why you write "I can not write fprint for each line."

2 Comments

ita on 12 Jul 2013

I think that I was not clear, sorry for my english. The idea is: matlab will evaluate 8 numbers (span of wing, thickness of airfoil,...) and these data will be used to write the .dat (this .dat is the file that my CFD program reads and it contains all specifications of the aircraft). So, to make Matlab to write the .dat for me I should write on the script a fprintf(fid,'...\n') for each line, and this is not feasable.

per isakson on 12 Jul 2013

"and this is not feasable." Why? I cannot see any reason why not.

Let me get this clear. You write "Here is an extract of the program:", but the following lines are they not an excerpt of a .dat-file, i.e they display the required format of the .dat-file? That is, the result of the Matlab program, which you are developing.

         CASO TESTE  LE e LDireito
    <  MACH  ><  ALPHA >[  BETA  ]<   RE   ><  CAX   ><   SW   >
       0.840    0.30000     0.     33000000.   3.194    72.7200
    [   ICL  ][   CL   ][  DCLDA ]
       0.        .45      .10
    [  PSE   ][ DELWING][  IBEAM ][  IAIL  ][  IROT  ][  IBLF  ]
        1.        0.        0.        0.        0.         0.
    [  PA1   ]
       0.70
    [  PA2   ]
       .77

This row

    CASO TESTE  LE e LDireito

is it a file-header, or is repeated throughout the .dat-file?

Then follows five pairs of one column header row and one data row. Is that correct? You write "evaluate 8 numbers [...] and these data will be used to write the .dat ", however I count to 17 numbers.

The .dat-file should contain 2700 groups of these five pairs of rows. Correct?

per isakson

Contact us