How to map a scalar to a vector?

4 ビュー (過去 30 日間)
Sanjana Sankar
Sanjana Sankar 2019 年 7 月 31 日
コメント済み: Sanjana Sankar 2019 年 8 月 1 日
I want to map a letter to a a vector.
Example: a is mapped to [ 0 0 0 0 1]
b ia mapped to [0 0 0 1 0] and so on.
The containers.Map function does not help me with this regard. Is there any other way to do the mapping?
Thanks in advance!

採用された回答

Walter Roberson
Walter Roberson 2019 年 7 月 31 日
Map = dec2bin(('a' :'z') - 'a' + 1, 5);
Word = 'hello' ;
Map(Word(:) - 'a' + 1,:)
  3 件のコメント
Walter Roberson
Walter Roberson 2019 年 7 月 31 日
Create a character vector that contains all of the permitted characters. You can build it in pieces using [] if that helps.
Then
Map = dec2bin(1:numel(PermittedChars)) ;
[~, idx] = ismember(Word, PermittedChars);
Result = Map(idx, :);
Sanjana Sankar
Sanjana Sankar 2019 年 8 月 1 日
Thanks a lot!

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

その他の回答 (0 件)

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by