user3011154
user3011154

Reputation: 11

converting number to vector of number matlab

I want to convert an input, lets say 012 into [0 1 2], once that is done i want to convert array of number into letters.

[0 1 2] ---> abc where 0=a, 1=b, 2=c and so on.

I want to do this without using any built in Matlab function

This is what I have

elseif isnumeric(result) % This else if statement will check if input is a number
alph = 'abcdefghijklmnopqrstuvwxyz';
letters1 = alph(result); % This will convert letters to numbers
disp(letters1); 
disp(' converted number to letters');

This code only works when the input is an array and it won't work for an input of 0.

How can I do this?

Upvotes: 0

Views: 134

Answers (1)

Daniel
Daniel

Reputation: 36710

Working with the ascii-representation of the chars, this is very simple:

char(result+'a')

For 0 the result is a, for 1 the result is a+1 which is b...

Upvotes: 1

Related Questions