フィルターのクリア

Writing parameters to a text file

9 ビュー (過去 30 日間)
Brenden
Brenden 2011 年 6 月 22 日
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
Arturo Moncada-Torres 2011 年 6 月 22 日
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 Center および File ExchangeText Data Preparation についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by