How to assign desired names for created files by Matlab?

Hello
my Matlab code saves each matrix as a csv file at the end. The problem is the file names. I want names to be taken from a calumn of names such as [b12;b20;b75;b151], one after each other. How should I assign each element of this vector as a file name? I appreciate if someone can help in this.

 Accepted Answer

Simple example
for i = 1:5
s = sprintf('data%d',i);
A = rand(3);
writematrix(A,s)
end

4 Comments

Dear Darova
I think there is a misunderstanding about my question. I need some names that are already listed in a column, to be assigned as a name, for csv files that are being created in my code. As I undestood, your code creates random names and saves them in a matrix... This is a different story.
I hope it is clear now :)
See my impoved script below
s = {'b12' 'b20' 'b75' 'b151'};
for i = 1:length(s)
writematrix(A,s{i})
end
Thanks Tara
This works. I just need to adjust it in my code. I will ask if there was an issue doing it :)
I will be here waiting

Sign in to comment.

More Answers (0)

Categories

Tags

Asked:

on 28 Apr 2020

Commented:

on 28 Apr 2020

Community Treasure Hunt

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

Start Hunting!