How can I change the name of my vector of each iteration?

5 visualizaciones (últimos 30 días)
Mariana
Mariana el 11 de Jul. de 2014
Comentada: Mariana el 11 de Jul. de 2014
Hello everyone
I have this code that generates a vector (different length in each iteration). I called it SEC1 cause I thought I could find a way to make the 1 run with the i value, but I can't. What can I do?
Thanks for the help.
n = length(S);
for ii = 1:n;
a = M(ii,1);
b = M(ii,2);
SEC1 = unique(IdD(a:b));
end

Respuesta aceptada

David Sanchez
David Sanchez el 11 de Jul. de 2014
Use eval:
S = rand(3,1); % sample data to test the script
n = length(S);
for ii = 1:n;
a = M(ii,1);
b = M(ii,2);
array_name = sprintf('SEC%g = unique(IdD(a:b))',ii);
eval(array_name);
end
go to eval documentation for more information about the function
help eval
doc eval
  1 comentario
Mariana
Mariana el 11 de Jul. de 2014
I was trying similar things for hours and couldn't make it work.
Thanks a lot!!

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Loops and Conditional Statements en Help Center y File Exchange.

Etiquetas

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by