Search Contact information
University of Cambridge Home Department of Engineering
University of Cambridge >  Engineering Department >  computing help
next up previous contents
Next: Vectorising Up: Miscellaneous Previous: Stopping

Program-generated names and commands

This shows how to generate variable names 'on the fly'. This is especially useful when you're running batch jobs and want to save results into several files.
% 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