How to save multiple matrices into multiple text files?

I have a series of matrices like A1,A2,A3,A4.
I want to save them into txt files named like file1, file2, file3, file4 respectively.

 Accepted Answer

It is a very bad idea to create variables with indices hidden in the name, see TUTORIAL: How to avoid Eval .
If the variables are store in a cell like A{1}, A{2}, ... the saving works easily using a loop:
for iA = 1:numel(A)
filename = sprintf('file%d.txt', iA);
dlmwrite(filename, A{iA});
end

More Answers (1)

Categories

Asked:

on 30 Nov 2018

Commented:

on 1 Dec 2018

Community Treasure Hunt

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

Start Hunting!