How to Create a New DAT File in Matlab

104 27
    • 1). Create your file handler. A file handler is a Matlab variable that contains the location of the file you create. The following code creates the file handler:

      FILE * file;

    • 2). Create the DAT file. You use the "fopen" function to create files in Matlab. The following code creates your file:

      file = fopen('myfile.dat','w');

      The "w" letter in this line of code indicates to the compiler that you want to "write" data to the file. If you want to simply read the file, use the "r" character.

    • 3). Write some data to the DAT file. The following code writes a simple line of text to your file:

      fputs ("my first dat file",file);

    • 4). Close the file. After you are finished writing to the DAT file, close it to release it from memory. The following code closes the file:

      fclose(file);

Source...
Subscribe to our newsletter
Sign up here to get the latest news, updates and special offers delivered directly to your inbox.
You can unsubscribe at any time

Leave A Reply

Your email address will not be published.