MATLAB: How to replace random integers with the alphabet (1=A, 2=B, and so on)

alphabetcharintegersreplace

Hi, Thank you for helping me
I am trying to replace a square matrix of random integers with the alphabet
For instace: A = [1 2; 3 5] should give you A = [A B; C E]
My code is:
clear all; clc;
n = input('Choose your square matrix dimension: ')
N = round((27)*rand(n))
A = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
for kk = 1:length(N)*2
N(kk) = A(kk);
end
N
I do not know how to replace the numbers with the alphabet.
Could you help, please?
Thank you very much
Have a nice day.

Best Answer

An easiest way to generate random integers is to use randi. As for your replacement it's achieved with simple indexing:
n = input('Choose your square matrix dimension: ');
N = randi(26, n);
A = 'A' : 'Z';
%replacement, note that this requires that all N are strictly positive integer:
NewN = A(N)