MATLAB: Convert a vector in Character array after a for loop

arraycharcharactercharacter arrayelse iffilling a vectorfor loopMATLABswitch casevector

Hi, given the following code
n=length(x)
f = zeros(1,n)
for i = 1:n
if x(i) == 1
f(1,i) = 22;
elseif x(i)==2
f(1,i) = 23;
elseif x(i)==3
f(1,i)= 21;
elseif x(i)==4
f(1,i) = 23;
elseif x(i)==5
f(1,i)= 24;
end
end
C= char (f)
I don't know why but the 'char' conversion doesn't work giving to me the following
so with nothing inside the vector, that I need later for a switch case.
Do you know how to fix the problem?

Best Answer

Avoiding character manipulations using basic indexing:
>> x = [1,2,3,1];
>> V = 'A':'Z';
>> V(x)
ans = ABCA