MATLAB: How to create matrix of string and use it in mathematic operation

matrix

example
a=[1;0;1;1;0]
b=[ben;james;mike;ralph;will]
c=a.*b
c=[ben;mike;ralph]

Best Answer

Use a cell array of strings for b and use logical indexing instead of a.*b,
>> b={'ben';'james';'mike';'ralph';'will'};
>> a=logical([1;0;1;1;0]);
>> b(a)
ans =
'ben'
'mike'
'ralph'