How to turn a string into a variable name within a loop?
<p>I developed a matlab code that I now have to modify to turn into a loop. I would like to save my data at every iteration with a different variable name (without changing the variable name at the beginning of every iteration). Here I provide an example to explain what I want to do:</p>

<pre><code>Matrix = rand(1000,3);
Dominated = 0;
Flag = 0;
k=0;
for k=1:10
   for i = 1:size(Matrix,1)
      Dominated = i
   end
    genvarname(sprintf('Dominated_%d',k)) = Dominated(:,:);
 end
</code></pre>

<p>however, if I execute this code, it does not provide me with a variable called "Domianted_1", "Domanted_2" and so on, but with a a variable called "genvarname" (replaced at every iteration) containing what was done into my code. How can I modify the code to get a different variable name at every iteration?</p>