Application of "csvwrite(filename,M)" with different filename?

2 Ansichten (letzte 30 Tage)
D.Chehov
D.Chehov am 12 Apr. 2012
Hello to all,
There are several loop iterations in my code,the result from the first one is used as an input in the second and so on. I'd like to know how to write the results from every loop in a text-file, whose name contains the number of the loop? Also, have you got an idea how to write a command or code that use this text-file as an input for the next loop that follow!
Thank you in advance and regards!
  1 Kommentar
Jan
Jan am 12 Apr. 2012
Usually answers match your problem more exactly, if you post the code and ask an explicit question. Perhaps your problem is the creation of the text file in a specific format. But I assume, you are looking for a method to create the file names dynamically.

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Jan
Jan am 12 Apr. 2012
See: FAQ: process a sequence of files. And if you are there already, ready the other topics also.
FilePath = tempdir;
for i = 1:10
FileName = sprintf('file%02d.dat', i);
FID = fopen(fullfile(FilePath, FileName), 'w');
if FID == -1, error('Cannot open file for writing'); end
fprintf('%g %g\n', rand(2, 2));
fclose(FID);
end
The reading works equivalently.
Instead of using files to carry the input data, you can use the data directly in the next iteration.

Weitere Antworten (0)

Kategorien

Mehr zu Environment and Settings finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by