How to convert a matrix to a string array:

2 visualizzazioni (ultimi 30 giorni)
SM
SM il 9 Mag 2021
Commentato: SM il 2 Lug 2021
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!

Risposta accettata

Andrei Bobrov
Andrei Bobrov il 9 Mag 2021
"A" + R(1,:)' + R(2,:)'
  4 Commenti
Walter Roberson
Walter Roberson il 10 Mag 2021
cell2mat(arrayfun(@(s)sscanf(s, "%*c%1d%1d"),Q,'UniformOutput',false)).'

Accedi per commentare.

Più risposte (1)

Walter Roberson
Walter Roberson il 9 Mag 2021
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"

Categorie

Scopri di più su Characters and Strings in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by