1

I have the cell array of number matrices as follows:

  c= {[1,2,3,4] [1,2,4,3]   [1,3,2,4]}

Denoted that 1=A, 2=B, 3=C,4=D.How can I convert c into the cell array of strings as follows?

 s= {[A,B,C,D]  [A,B,D,C]   [A,C,B,D]}

And how can we generalize this rule such as 1 to 7 and A to G ... ?

1
  • Do you mean: s = {['A', 'B', 'C', 'D'], ['A', 'B', 'C', 'D'], ['A', 'B', 'C', 'D']} Commented Mar 17, 2017 at 9:09

1 Answer 1

4

If you by [A,B,C,D] intend

['A','B','C','D'] => 'ABCD'

that is, to concatenate all of them to a single string, you could add 64 to each number (to get the proper ASCII-coding) and covert the numbers to a char.

s = cellfun(@(x) char(x + 64), c, 'UniformOutput', false);
s = 
     'ABCD'    'ABDC'    'ACBD'
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.