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

2 vues (au cours des 30 derniers jours)
D.Chehov
D.Chehov le 12 Avr 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 commentaire
Jan
Jan le 12 Avr 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.

Connectez-vous pour commenter.

Réponse acceptée

Jan
Jan le 12 Avr 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.

Plus de réponses (0)

Catégories

En savoir plus sur Environment and Settings dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by