Creating a translator in MatLab

Viewed 77

I am trying to create a simple program in Matlab where the user can input a string (such as "A", "B", "AB" or "A B") and the program will output a word corresponding to my letter.

Input | Output
A        Hello
B        Hola
AB       HelloHola
A B      Hello Hola

This is my code:

A='Hello'; B='Hola';
userText = input('What is your message: ', 's');
userText = upper(userText);

    for ind = 1:length(userText)
        current = userText(ind);
        X = ['The output is ', current];
        disp(X);

    end

Currently I don't get my desired results. I instead get this:

Input | Output
A       The output is A
B       The output is B

I'm not totally sure why X = ['The output is ', current]; evaluates to The output is A instead of The output is Hello.


Edit:

How would this program be able to handle numbers... such as 1 = "Goodbye"

4 Answers
Related