필터 지우기
필터 지우기

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 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