Array content: Combine individual value into one single value & after substitution

Hello, For example, I have the following arrays: (1) X = [1 2 1 2 3] (2) Y = [1 3 2 1] (3) Z = [1 3 3 2 1 2 2 1 3] I would like to substitute 1 ==> A, 2===> B, and 3 ===> C. After that, I would like to change the array into a string, for example: Y = [1 3 2 1] Y*= [A,C,B,A] Y** = ACBA where ACBA is a string that can be displaced on the Edit Box in GUI....
I can't individually extract the numbers because I have a number of arrays, and each of them has different numbers of individual elements, and will change depending on the input. I also have a hard time doing the first step: Substituting 1 with A, for example. And I am not sure how to change an array into a string with all the individual elements becoming a word...
Many thanks!

 採用された回答

Walter Roberson
Walter Roberson 2011 年 3 月 17 日
alpha = 'A':'C';
Y__ = alpha[X];
set(handles.editbox1_handle, 'String', Y__);

2 件のコメント

Paulo Silva
Paulo Silva 2011 年 3 月 17 日
Walter you have [] instead of () on the second line
Walter Roberson
Walter Roberson 2011 年 3 月 20 日
Atch, that's what I get for working with two computer languages at the same time. :(

サインインしてコメントする。

その他の回答 (1 件)

Paulo Silva
Paulo Silva 2011 年 3 月 17 日
X = [1 2 1 2 3]
char(X+64)

3 件のコメント

Walter Roberson
Walter Roberson 2011 年 3 月 17 日
char(X-1+'A') is probably clearer to read.
Using char() like this works well if the values are consecutive. The array based approach I posted works for arbitrary symbol orders.
Paulo Silva
Paulo Silva 2011 年 3 月 17 日
yes you are right, I also didn't know we could do 'A':'C' just like we do with numbers, that's cool :)
K
K 2011 年 3 月 20 日
These works very well... many thanks!

サインインしてコメントする。

カテゴリ

ヘルプ センター および File ExchangeStructures についてさらに検索

製品

タグ

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by