writing a text file from compose


Answers
-
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
0 -
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
0 -
Thanks for your help. I needed to create a table with frequency and amplitude as inputs
0 -
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
0 -
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?
0 -
Hello Saransakthi,
are you looking for something similar to this?
Cheers,
Lorenzo
0 -
Thanks for your help. Your code works for me.
Cheers.
0