Jump to content
Saransakthi

writing a text file from compose

Recommended Posts

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

 

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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? 

 

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
You are posting as a guest. If you have an account, please sign in.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...