필터 지우기
필터 지우기

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

조회 수: 706 (최근 30일)
Anne Nguyen
Anne Nguyen 2019년 10월 15일
댓글: Stephen23 2020년 6월 18일
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.

채택된 답변

Stephen23
Stephen23 2019년 10월 15일
편집: Stephen23 2019년 10월 15일
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.
  댓글 수: 3
Pete Marsh
Pete Marsh 2020년 6월 18일
I get the difference between the char vector and a string array. What is the difference between the string array and a cell array?
Thanks
Stephen23
Stephen23 2020년 6월 18일
"What is the difference between the string array and a cell array?"
Well, they are both kinds of container arrays, but the similarities basically end there.
A cell array is a totally universal container that can hold any kind of array (even other cell arrays), whereas a string array specifically contains character vectors and nothing else. Because of this the string array has a bunch of methods and overloaded functions that offer convenient string manipulation:
More discussions on this topic:

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by