Using char to convert a numerical array into string
Afficher commentaires plus anciens
Hi everyone, I'm new on Matlab and I'm practicing.. I have a problem using char to convert an ASCII array into a string. I post you my code to better understand what is my problem:
s1='STRING'; %new string
n=length(s1); %length of string
k=3; %k number
char=zeros(1,n);
char_ASCII=zeros(1,n);
newascii=zeros(1,n);
for i=1:n
char(i)=s1(i);
char_ASCII(i)=double(char(i)); %from string to numeric array with double
if ( char_ASCII(i)==32) %if blank space don't do anything
newascii(i)=32;
else
newascii(i)=char_ASCII(i)+k; %otherwise add +k to all cell of array
end
end
Now, I've to use CHAR on my array 'newascii' to get back my modified string, but if I try to do that it returns me an error "Index exceeds matrix dimensions." I've read the help of char but I can't understand where is the error. Hope you can help me, Thank you so much!
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Characters and Strings dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!