So the following code can left pad a string with spaces keeping a max length of max_len (spaces and string included).
max_len = 20;
spacing_arg = ['% ', max_len,'s'];
padded_string = sprintf(spacing_arg, str);
Now how to do it efficiently with right padding?
Is this what you mean?