%% SL 16
sprintf('Value of pi is %0.5f, value of 5*pi is %0.5f.', pi, 5*pi)
    
x = 50;
sprintf('This is %d%%', x)
     
tx = 'test_A';
sprintf('This is a measurement set: %s', tx)

%% SL 23
s = 'Do what you can, with what you have, where you are.';
% Several alternatives:
s(s ~= ' ')
s(s > ' ')
s(s > 32)

nYou = length(strfind(s, 'you'));

%% SL 38
M = @(x)[sin(x), cos(x)];
% Saving
fileID = fopen('testFile.txt','w+');
fprintf(fileID, '%s\n', func2str(M));
fclose(fileID);
% Loading
fileID = fopen('testFile.txt','r');
A = fgetl(fileID);
fclose(fileID);
% Evaluation
M = str2func(A)
M(1)

%% SL 48
st = 'how are you?';
length(strfind(st, ' '))
sum(st == ' ')

st = 'MATLAB is CaSe sEnSiTiVe!!!';
st = lower(st)
length(st)

%% SL 50 (put the following code into standalone file, name it cuboid.m)
function out = cuboid(a, b, c, attribute)
out = [];
if nargin < 4
   fprintf('Wrong input');
   return
end

switch attribute
   case 'volume'
      out = a*b*c;
   case 'area'
      out = 2*(a*b+b*c+c*a);
   case 'diagonal'
      out = sqrt(a^2+b^2+c^2);
   otherwise
      fprintf('Wrong input');
end
end