MATLAB: Possible erroneous lint message when using SPRINTF

lintsprintf

Hello all,
I am using SPRINTF to format a string for a plot title, like so:
str = sprintf('The title %s', f)
I get the lint message "The function SPRINTF is apparently called with a cell array (argument 2)".
The variable f is defined as such: If the value of another variable n equals 1 then f is defined as a cell array of strings {'1Hz', '2Hz', '3hz'}. If n equals 0 then f is simply a 1×3 character array ['3Hz'].
When I use SPRINTF in the instance above, the value of n is always 0, so f in this case would never be a cell array. Yet MATLAB seems to assume that, because f is sometimes a cell array then it is a cell array (which in this case it is not).
Basically, is there a way of suppressing this message? I like my lint checker to be green and it's bugging me 🙂
Thanks,
Louis Vallance

Best Answer

Redefine the n = 0 case as f = {'3Hz'} and then sprintf() of f{1}