Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

dlmwrite usage withing loop

Tags:

loops

save

matlab

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

like image 334
user1722948 Avatar asked Feb 23 '26 03:02

user1722948


1 Answers

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
like image 89
Andrey Rubshtein Avatar answered Feb 25 '26 18:02

Andrey Rubshtein



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!