Data type update: Strings
5 views (last 30 days)
Show older comments
These questions all surround the same topic, so I didn't want to separate to different questions as per the usual way of posting these things. If re-organization is better, feel free to edit.
(1) Why did Mathworks wait until R2017a to utilize double quotes with strings?
(2) What are some of the major limitations with using " (double quotes) versus ' (single quotes)?
(3) Referencing rules appear to be the same as with cell arrays. Please confirm as true or inform us as to any differences.
(4) isstr() and ischar(): These return "<string>" as non-string and non-char (values of 0), whether expressed in the open, in a cell array, or in a nested structure. Is that intentional? They continue to return 1 for single quotes, though (i.e., '<string>').
(5) cellstr(): This is a very welcome function, saving on time in coding. As it is part of the same family as num2str(), for example, should it be re-labeled in a future release as str2cell()? Not critical on this point, just inquiring.
Thanks!
2 Comments
Walter Roberson
on 10 Apr 2017
cellstr itself has existed for a long time. Are you referring to some particular functionality for it?
Stephen23
on 10 Apr 2017
Edited: Stephen23
on 10 Apr 2017
- The string type was introduced in R2016b, so I don't see until 2017b as a very long wait.
- They are different data types, which have different features, different abilities, and different use cases. You are basically asking a question as general as "what are the advantages of integer uint8 compared to floating point single?", which is a question with millions of potential differences. The differences are the data types themselves. Use the data type that suits your purposes.
- ???
- According to the MATLAB documentation, both ischar and isstr test for character arrays. A cell array, etc. is not a character array, so what you are seeing is exactly as documented. Why ask us when you can look in the documentation yourself.
- cellstr has existed since before R2006a (as its documentation states). Changing its name would break quite a bit of code, but it might happen.
Answers (1)
Walter Roberson
on 11 Apr 2017
"(1) Why did Mathworks wait until R2017a to utilize double quotes with strings?"
The MATLAB parser is apparently not well structured, as it needs to deal with a number of edge cases that users seldom think about. Changes to the language accepted by the parser require thorough testing. Mathworks was not able to resolve all of the difficulties in time for R2016b when strings were introduced.
The question could be regressed to why they did not start this change earlier.
Mathworks has learned a fair bit in the last few releases about taking advantage of objects and {} and () syntax to create apparent new behavior without having to make large internal changes. This might simply have been the point at which they realized that it was practical to implement double-quoted strings without having to create new data structures at the binary / threaded interpreter level.
0 Comments
See Also
Categories
Find more on Characters and Strings in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!