How to convert a matrix to a string array:

I have a matrix:
R=[1 2 1 3 2 3 1;1 1 2 1 2 2 3];
that i want to convert to:
Q=["A11","A21","A12","A31","A22","A32","A13"];
How can I do that?
Appreciated!

 採用された回答

Andrei Bobrov
Andrei Bobrov 2021 年 5 月 9 日

1 投票

"A" + R(1,:)' + R(2,:)'

4 件のコメント

Scott MacKenzie
Scott MacKenzie 2021 年 5 月 9 日
Nice. I submitted an answer, but deleted it when I saw this one. Awesome.
SM
SM 2021 年 5 月 9 日
編集済み: SM 2021 年 5 月 9 日
What an excellent asnwer! Really awesome. Is it possible to do the reverse, i.e. string to the matrix?
Walter Roberson
Walter Roberson 2021 年 5 月 10 日
cell2mat(arrayfun(@(s)sscanf(s, "%*c%1d%1d"),Q,'UniformOutput',false)).'
SM
SM 2021 年 7 月 2 日
Thank you

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

その他の回答 (1 件)

Walter Roberson
Walter Roberson 2021 年 5 月 9 日

1 投票

R=[1 2 1 3 2 3 1;1 1 2 1 2 2 3]
R = 2×7
1 2 1 3 2 3 1 1 1 2 1 2 2 3
compose("A%d%d", R(1,:).', R(2,:).').'
ans = 1×7 string array
"A11" "A21" "A12" "A31" "A22" "A32" "A13"

1 件のコメント

SM
SM 2021 年 5 月 9 日
You are awesome! Thank you.

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

カテゴリ

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

タグ

質問済み:

SM
2021 年 5 月 9 日

コメント済み:

SM
2021 年 7 月 2 日

Community Treasure Hunt

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

Start Hunting!

Translated by