Search Contact information
University of Cambridge Home Department of Engineering
University of Cambridge >  Engineering Department >  computing help
next up previous contents
Next: Vectorised code Up: Examples Previous: Adding buttons and menus

Program-generated names and commands

This shows how to generate variable names 'on the fly'.
% A1, A2, A3, and A4 are created and set to 3
for i=1:4
s=sprintf('A%d= 3',i);
eval(s);
end;

% This shows how to run a command that's stored in a string
str=input('Type in a command ','s') 
eval(str)


© Cambridge University Engineering Dept
Information provided by Tim Love
2006-07-24