What is the difference between string arrays and cell arrays of character vectors?
Show older comments
R2016b allows you to create string arrays, and R2017A allows you to use the double-quote syntax for specifying string literals. What is the practical difference between a string array (e.g ["one", "two"]) and a cell array of character vectors (e.g. {'one', 'two'}). Aside from minor conveniences like "strlength" (which could easily have been implemented to operate on cell arrays of character vectors), why should I care about this? Am I missing something?
3 Comments
dpb
on 25 Apr 2017
I don't have the new release as not able to run 64-bit here as yet, but I'd hazard the biggest reason to use the new string class over cellstr arrays is that it should let you get rid of the ugly cellfun gyrations need to do searching in cell arrays. The cellstr require such abhorences as the following
function [is,idx]=isFundName(pool,name)
% isFundName(funds,name) returns logical array of the requested
% fund name within the fund name or pool
%
% [isName,locName]=isFundName(NAMELIST,NAME)
% returns logical array and optionally the index location within
% the name list
if strcmp(class(pool),'dataset')
is=(~cellfun('isempty',strfind(pool.Fund,name)));
else
is=(~cellfun('isempty',strfind(pool,name)));
end
idx=find(is);
>>
The string functions such strfind over the cell array return another cell array so such nonsense as the above is needed.
Hopefully strings will let one write the above as simply a string search.
Chris Volpe
on 25 Apr 2017
Walter Roberson
on 25 Apr 2017
Is there any non-numeric data structure that could not be implemented as a struct and then adding functions to the language ?
Accepted Answer
More Answers (2)
Steven Lord
on 25 Apr 2017
1 vote
You may find today's post from Loren's blog interesting and informative. If you have questions or feedback, as Dave wrote, "Expect to hear more from me on this topic. And please share your input with us by leaving a comment below. We're interested to hear from you."
Walter Roberson
on 25 Apr 2017
0 votes
Students keep trying to use == to compare strings, and keep trying to use () to store strings. Making MATLAB easier for students is a practical difference.
Now as to whether it is faster or whether there are additional meaningful features... those are different questions ;-)
1 Comment
What about the search issue--are strfind and friends now string aware? If so, that would be a_good_thing (tm).
From the blog Steven L reference, it appears "not yet". I'd echo the sentiments of another poster there that it would be better to hold off the introduction of these new features until they're really "ready for prime time" instead of just interesting little tidbits stuck on like the candy commercial...
How are strings displayed -- do they have a double-quote around them a la the single for cell strings to differentiate their appearance?
This is a 'yes' it seems...makes sense; presumed so but curious.
Categories
Find more on Data Type Identification 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!