Possible erroneous lint message when using SPRINTF

2 views (last 30 days)
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 1x3 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

Accepted Answer

Walter Roberson
Walter Roberson on 26 Mar 2014
Redefine the n = 0 case as f = {'3Hz'} and then sprintf() of f{1}

More Answers (0)

Categories

Find more on Characters and Strings in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!