MATLAB Answers

Difference between using single quotes ('xyz') and double quotes ("xyz") in formatspec

4 ビュー (過去 30 日間)
Ranjan Sonalkar
Ranjan Sonalkar 2021 年 6 月 1 日
コメント済み: Steven Lord 2021 年 6 月 1 日
What is the difference between using single quotes ('xyz') and double quotes ("xyz") in formatspec?

採用された回答

James Tursa
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
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)
c = '1 2 3'
s = sprintf("%d %d %d", 1:3)
s = "1 2 3"
whos c s
Name Size Bytes Class Attributes c 1x5 10 char s 1x1 150 string

サインインしてコメントする。

その他の回答 (0 件)

製品

Community Treasure Hunt

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

Start Hunting!

Translated by