% this is a script file to demonstrate formatted printing and scanning
Exa = 1;  % choose the example to run

switch Exa
  case 1                 % printf
    sprintf('the square of %i is %i\n',5,25)
    sprintf('this is pi: %10.6e\n',pi);
    st = sprintf('this is pi: %10.6e\n',pi);
    disp(st)
  case 2                 % scanning
    s = 'pi equals 3.14 approximately';
    [head, piApprox, tail] = sscanf(s,'%10c%e%s','C')
    % does not work in Matlab, use textscan()
  case 3                 % conversion
    name = toascii('BFH-TI')  % not in Matlab
    s = int2str(4711)
    typeinfo(s)
    s+1
  case 4                 % generate list of file names
    basename = 'myfile'
    for i = [1 2 3 7 11 999]
      [basename,sprintf('%03d',i),'.dat']
    end%for
end%switch
