help with creating certain function for setting elements in one matrix to another
情報
この質問は閉じられています。 編集または回答するには再度開いてください。
古いコメントを表示
want to make function that takes in text, and then creates a matrix that sets each element to one of the ascii code elements
for example: [abcdef] would get set to [1 2 3 4 5 6]
and [help] would get set to [8 5 12 16]
pls help
0 件のコメント
回答 (1 件)
the cyclist
2017 年 11 月 4 日
Here's one way:
alphabet = 'abcdefghijklmnopqrstuvwxyz';
[~,vec] = ismember('help',alphabet)
9 件のコメント
Andrei Bobrov
2017 年 11 月 4 日
discretize('help'-'a',('a':'z') - 'a')
Jessie Ray
2017 年 11 月 4 日
Jessie Ray
2017 年 11 月 4 日
the cyclist
2017 年 11 月 4 日
編集済み: the cyclist
2017 年 11 月 4 日
[~,vec] = ismember('jsdbsfb',alphabet)
or
charvec = 'jsdbsfb';
[~,vec] = ismember(charvec,alphabet)
Just define it as a variable, and pass that variable.
str = 'jsdbsfb';
[~,vec] = ismember(str,alphabet)
Note that a simpler way to generate the alphabet is to use the colon, which also reduces the chance of missing a letter:
str = 'jsdbsfb';
[~,vec] = ismember(str,'a':'z')
Jessie Ray
2017 年 11 月 4 日
the cyclist
2017 年 11 月 4 日
So, maybe next time give a complete description of your problem first?
Jessie Ray
2017 年 11 月 4 日
この質問は閉じられています。
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!