MATLAB Answers

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..

  0 Comments

Tags

Products

2 Answers

Answer by Azzi Abdelmalek
on 14 Feb 2013
 Accepted answer

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

  7 Comments

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


Answer by Jan Simon
on 14 Feb 2013

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)

  0 Comments


Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

MATLAB Academy

New to MATLAB?

Learn MATLAB today!