フィルターのクリア

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

1 回表示 (過去 30 日間)
eri
eri 2012 年 10 月 24 日
example
a=[1;0;1;1;0]
b=[ben;james;mike;ralph;will]
c=a.*b
c=[ben;mike;ralph]

採用された回答

Matt J
Matt J 2012 年 10 月 24 日
編集済み: Matt J 2012 年 10 月 24 日
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'

その他の回答 (1 件)

Matt J
Matt J 2012 年 10 月 24 日
編集済み: Matt J 2012 年 10 月 24 日
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 件のコメント
Matt J
Matt J 2012 年 10 月 24 日
編集済み: Matt J 2012 年 10 月 24 日
I never get tired of this one! :-)

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeDates and Time についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by