Effacer les filtres
Effacer les filtres

how to create matrix of string and use it in mathematic operation?

1 vue (au cours des 30 derniers jours)
eri
eri le 24 Oct 2012
example
a=[1;0;1;1;0]
b=[ben;james;mike;ralph;will]
c=a.*b
c=[ben;mike;ralph]

Réponse acceptée

Matt J
Matt J le 24 Oct 2012
Modifié(e) : Matt J le 24 Oct 2012
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'

Plus de réponses (1)

Matt J
Matt J le 24 Oct 2012
Modifié(e) : Matt J le 24 Oct 2012
Speaking of mathematical operations with strings, ever wonder what you get when you cross a cat with an owl?
>> cross('cat','owl')
ans =
-3328 2184 1014
  1 commentaire
Matt J
Matt J le 24 Oct 2012
Modifié(e) : Matt J le 24 Oct 2012
I never get tired of this one! :-)

Connectez-vous pour commenter.

Catégories

En savoir plus sur Dates and Time dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by