- http://matlab.wikia.com/wiki/FAQ#Why_is_it_advised_to_avoid_using_the_.22eval.22_function.3F
- http://www.mathworks.co.uk/support/tech-notes/1100/1103.html
Setting variable names from a character array
6 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
hi,
I have a character array, for example:
vars = ['X';'Y']
I want to assign the name of an element in vars to a double array, such as:
for i=1:2
char(vars(i,:)) = rand(10,1)
end
Unfortunately this does not work as I am obviously attempting to equate a character array to a double array of different length. Instead of course what I was attempting to do is name a double array from a predefined list.
Please help!
thx
0 comentarios
Respuesta aceptada
Jan
el 23 de Sept. de 2011
Do not do this. Creating variables dynamically a is common and frequent source of errors. In addition is is slow. See:
Use either an array, cell array or struct:
vars = {'X', 'Y'};
S = [];
for i = 1:2
S.(vars{i}) = rand(10,1);
end
Or:
C = {};
for i = 1:2
C{i} = rand(10,1);
end
0 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Logical en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!