writing a text file from compose

Altair Forum User
Altair Forum User
Altair Employee
edited October 2020 in Community Q&A

Hi, I need to write/generate a .txt file from compose. Can someone help? Thanks in advance.

 

Tagged:

Answers

  • L Moretti
    L Moretti New Altair Community Member
    edited March 2019

    Hi Saransakthi,

    write a .txt file from Compose is as simple as this:

     

    clc,clear,close all
    fid = fopen('newtxtfile.txt','w');
    fwrite(fid,'this is a .txt file');
    fclose(fid);

     

    What do you have to write?

    Cheers,

     

    L

     

  • robertavarela
    robertavarela New Altair Community Member
    edited March 2019

    You may also print your variables on the text file that you just created and opened:

    fprintf(fidout, 'Example of mixing text and variables: %.3f %.2f %8d\n', variable1, variable2, variable3);

    Where variable1 will be written with 3 decimal digits, variable2 with 2 decimal digits and variable3 as an integer. The command \n will break the line after you write all content.

     

    And you don't need to worry if your newtxtfile.txt is already in your folder... Once you create it again with Compose, it will overwrite the previous file, so you should not expect any kind of error saying that the file already exists.

     

    Regards,

     

    Roberta

  • Altair Forum User
    Altair Forum User
    Altair Employee
    edited April 2019

    Thanks for your help. I needed to create a table with frequency and amplitude as inputs

  • robertavarela
    robertavarela New Altair Community Member
    edited April 2019

    Saransakthi,

     

    Using the syntax I mentioned, you may put your frequency variable in variable1 and your amplitude in variable2, adjusting the decimal precision as you wish.

     

    After printing everything in your file using fprintf, it's a good practice to close your files (using fclose function in thi case)

     

    Regards,

     

    Roberta

  • Altair Forum User
    Altair Forum User
    Altair Employee
    edited April 2019

    Thanks,

             Also, I have plotted an FFT graph in compose. Is there a way to isolate the maximum amplitude and its corresponding frequency from the graph? 

     

  • L Moretti
    L Moretti New Altair Community Member
    edited April 2019

    Hello Saransakthi,

     

    are you looking for something similar to this?

     

     

    Cheers,

     

    Lorenzo

    Unable to find an attachment - read this blog

  • Altair Forum User
    Altair Forum User
    Altair Employee
    edited April 2019

    Thanks for your help. Your code works for me.

    Cheers.