how to assign characters?

if my input is a, then i should get always as u.... input is b means i should always get as w..... what techniques should be followed to achieve this.. should i use string concept..

 采纳的回答

data.a='u';
data.b='w'
x=input('input','s');
s=data.(x)

7 个评论

wow.. it works fine..thanks Abdel..
your answer suits the best for a single letter. now my input is siva. my answer should be tfjs. how to get it. next doubt is.. i can give any input of my own choice. it can be of any length of characters. to be in short, it should be as like encryption.
There is no difference
data.tfjs='siva';
x=input('input','s');
s=data.(x)
you fixed the word siva. i am not supposed to fix it... user may give any input
What do you mean? you said siva corresponds to tfjs. You have then to put it in your code or no? Or explain
Maybe you want this
data.a='u';
data.b='w'
x=input('input','s');
n=numel(x);
for k=1:n
s(k)=data.(x(k))
end
It works well for a single word... how about for a sentence

请先登录,再进行评论。

更多回答(1 个)

You can create a lookup table:
pool = repmat(char(0), 1, 255);
pool('a') = 'u';
pool('b') = 'w';
...
% Or together:
pool('ab') = 'uw'; % A strange indexing, but it works
And then:
c = 'a';
pool(c)

类别

在 帮助中心 和 File Exchange 中查找有关 Matrix Indexing 的更多信息

产品

标签

Community Treasure Hunt

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

Start Hunting!

Translated by