How to map a scalar to a vector?
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Sanjana Sankar
am 31 Jul. 2019
Kommentiert: Sanjana Sankar
am 1 Aug. 2019
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!
0 Kommentare
Akzeptierte Antwort
Walter Roberson
am 31 Jul. 2019
Map = dec2bin(('a' :'z') - 'a' + 1, 5);
Word = 'hello' ;
Map(Word(:) - 'a' + 1,:)
3 Kommentare
Walter Roberson
am 31 Jul. 2019
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, :);
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Mapping Toolbox finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!