Difference between using single quotes ('xyz') and double quotes ("xyz") in formatspec
64 次查看(过去 30 天)
显示 更早的评论
What is the difference between using single quotes ('xyz') and double quotes ("xyz") in formatspec?
0 个评论
采纳的回答
James Tursa
2021-6-1
编辑:James Tursa
2021-6-1
In MATLAB, single quotes ' ' are used to create char type variables, and double quotes " " are used to create string type variables.
Char type variables are simple rectangular arrays of characters:
String type variables are OOP objects that have many features that are not available with char type variables, such as creating arrays of varying length strings:
1 个评论
Steven Lord
2021-6-1
One difference that's specific to the circumstances of using them in a format specifier of a call to sprintf is that the result will be the same type as the format specifier as stated in the section of the documentation page that describes the str output.
c = sprintf('%d %d %d', 1:3)
s = sprintf("%d %d %d", 1:3)
whos c s
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Environment and Settings 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!