MATLAB Answers

Difference between ' (single quote) vs " (double quote)?

559 views (last 30 days)
When used in an fprintf or disp function, what is the difference between using only ' (single quote) vs using " (double quote)? Does fprintf and disp make a difference also regarding when using ' or " ? Thank you.

Accepted Answer

Stephen Cobeldick
Stephen Cobeldick on 15 Oct 2019
Edited: Stephen Cobeldick on 15 Oct 2019
In a nutshell:
  • single quotes define a character vector with size 1xN, where N is the number of characters between the quotes.
  • double quotes define a string array with size 1x1 (i.e. scalar, regardless of how many characters it has). You can think of string arrays as a kind of container for character vectors.
String arrays have some advantages, such as it is possible to have text data with exactly the same dimensions as corresponding numeric data, and there also exist many overloaded operations which perform useful implcit operations on strings. However they also require more memory, can be slower than using character vectors, and are not supported on MATLAB versions prior to R2016b.
"Does fprintf and disp make a difference also regarding when using ' or ""
In many situations where a character vector can be used a string scalar is also supported: read the online documentation for the specific functions to know what inputs it accepts. Providing a string/character vector can make a difference: for example, sprintf will return an output of the same class as its formatSpec input argument.


Sign in to comment.

More Answers (0)

Sign in to answer this question.