Writing parameters to a text file

7 次查看(过去 30 天)
Hello all,
I was hoping that someone could help me with writing a text file in matlab. What i have is a program that has many initial parameters and then goes through stages of calculations and graphing. at the end of the program i use the imwrite command to save the pictures however, what i am wondering is how to save a text file with a list of the initial parameters and what ever other information i want...
something of the form:
LOG INFORMATION
Wavelength:
Source to Object:
etc.
Thank you BN

采纳的回答

Arturo Moncada-Torres
Writing a text file in MATLAB is very easy. Take a look at the documentation for the function fopen, fprintf, and fclose.
doc fopen
doc fprintf
doc fclose
On a quick thought, a brief example:
fileID = fopen('myFileName', 'wt'); % Open and create file in text writing mode.
% Write the content to the log text file.
fprintf(fileID, ' =======================================\r\n');
fprintf(fileID, '|| LOG INFORMATION ||\r\n');
fprintf(fileID, ' =======================================\r\n\r\n\r\n');
fprintf(fileID, 'Wavelength\t%s\r\n', wavelength); % "wavelength" is a string.
fprintf(fileID, 'Source Object\t%s\r\n', sObject); % "sObject" is a string.
fprintf(fileID, 'Value\t%f\r\n', value); % "value" is a float.
fclose(fileID); % Close file.
Notice that \r\n is necessary for a new line in Windows (more information in fprintf documentation).

更多回答(1 个)

David Young
David Young 2011-6-22
See doc fprintf. This will do exactly what you want.

类别

Help CenterFile Exchange 中查找有关 Text Data Preparation 的更多信息

标签

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by