Filter löschen
Filter löschen

Writing parameters to a text file

9 Ansichten (letzte 30 Tage)
Brenden
Brenden am 22 Jun. 2011
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

Akzeptierte Antwort

Arturo Moncada-Torres
Arturo Moncada-Torres am 22 Jun. 2011
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).

Weitere Antworten (1)

David Young
David Young am 22 Jun. 2011
See doc fprintf. This will do exactly what you want.

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by