Matrix with numeric values

1 Ansicht (letzte 30 Tage)
Nathan McFall
Nathan McFall am 7 Apr. 2020
Bearbeitet: Nathan McFall am 7 Apr. 2020
I have assigned letters A through Z a numeric value of 1 through 26, respectively. I have been able to form a 26x19 matrix with these random numeric values. However, I do not know how to convert the entire matrix back to character form.
For example, if part of my matrix is [1 2 3 4], I want it to be [A B C D]. (Note: as said above, I have assigned variable A to equal 1, variable B to equal 2, etc.)
  1 Kommentar
Stephen23
Stephen23 am 7 Apr. 2020
"I have assigned letters A through Z a numeric value of 1 through 26..."
Sounds like a complex approach.
A much simpler use of MATLAB ("MATrix LABoratory") would be to use vectors/matrices to store your data.

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Birdman
Birdman am 7 Apr. 2020
Bearbeitet: Birdman am 7 Apr. 2020
N=4
A=1:N;
B=char(64+A)
'ABCD'
B(1)
'A'
B(2)
'B'
.
.
and so on. Change N and observe the results.
  3 Kommentare
Birdman
Birdman am 7 Apr. 2020
Because char makes conversions based on ASCII table.
Stephen23
Stephen23 am 7 Apr. 2020
Bearbeitet: Stephen23 am 7 Apr. 2020
"why do you have to say char(64 + A), rather than just doing char(A)?"
The character code for 'A' is 65:
MATLAB supports unicode characters up to 65535:

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu MATLAB finden Sie in Help Center und File Exchange

Tags

Noch keine Tags eingegeben.

Community Treasure Hunt

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

Start Hunting!

Translated by