iscellstr warning "To support string in addition to cellstr, include a call to 'isstring'" unavoidable?
Show older comments
When using the iscellstr function MATLAB always generates a warning "To support string in addition to cellstr, include a call to 'isstring'". Is there any way to avoid this warning besides supressing it with %#ok? Is there an alternate pattern i can use to avoid this warning?
2 Comments
Hitesh
on 11 Oct 2024
Hi @Max Heimann
Can you specify the version of MATLAB where you're experiencing this warning? Additionally, could you provide a sample code snippet that reproduces the warning?
Max Heimann
on 11 Oct 2024
Accepted Answer
More Answers (1)
Harald
on 11 Oct 2024
0 votes
Hi,
you can suppress this Code Analyzer warning in all files by right-clicking it and selecting "Suppress Message..." > In all files.
Please note that this will suppress the warning only for you and not for any colleagues. Also note that if you don't know the name of a warning anymore, you may have a hard time figuring out how to turn it back on.
If your application also works with string arrays such as ["abc", "def"], you might of course want to switch to isstring.
Also, I am wondering about the broader "why" behind using this function. For validating input arguments of a function, you may find arguments blocks a great alternative. A brief explanation of the idea: MATLAB will automatically check for data types and dimensions and perform conversions if possible. If conversions are not possible, it will automatically generate an error message. For more information, please see https://de.mathworks.com/help/matlab/ref/arguments.html.
Best wishes,
Harald
2 Comments
Max Heimann
on 14 Oct 2024
Harald
on 14 Oct 2024
If it is a reasonably small team, everybody could suppress the warning.
If the data is coming in as cell array of chars and you don't mind to continue working with strings afterwards, you could use arguments blocks like this:
function strOut = strfun(strIn)
arguments
strIn string
end
strOut = strIn;
Then, both
strfun({'abc', 'def'})
strfun(["abc", "def"])
would give
"abc" "def"
Best wishes,
Harald
Categories
Find more on Data Type Conversion 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!