user1722948
user1722948

Reputation: 31

dlmwrite usage withing loop

Is it possible to use dlmwrite within a loop ? my code is bit long, but i am stuck here ....

loop starts
{
file taken as input
some processing done over it
results saves in a variable "d"
**now i want to save the results of d to new text file**
display the results on Matlab
goes to next file until last file
}

for a single file without loop, this works fine

      dlmwrite('test.txt',d);

now what to do within loop to save the results every time with new file name, as every time new file is processing

like

dlmwrite('file1.txt',d);
dlmwrite('file2.txt',d);
.
.
.
.
.
.
dlmwrite('lastfile.txt',d);

All of my results are binary

Upvotes: 3

Views: 1462

Answers (1)

Andrey Rubshtein
Andrey Rubshtein

Reputation: 20915

You should use a loop and enumerate the file names:

    for i=1:numel(data)
         fileName = sprintf('file%d.txt');
         dlmwrite(fileName,data{i});
    end

Upvotes: 3

Related Questions