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

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?
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일
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"

카테고리

도움말 센터File Exchange에서 Characters 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