array of strings from an array of integers
91 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Scott Richardson
il 25 Apr 2013
Risposto: Walter Roberson
il 12 Feb 2021
Hi if I have an array of integers like this:
A=[123 456 789]
How do I get an array of strings, say named B, such that:
BB(1) = 123 (this is string 1) BB(2) = 456 (this is string 2) BB(3) = 789 (this is string 3)
What I am trying to do is use integer values as labels for my xtick labels, and cannot figure out how to do it. Thank you.
0 Commenti
Risposta accettata
Più risposte (2)
Steven Lord
il 12 Feb 2021
If you're using a release that supports the string array (which did not exist when the original question was asked) use string.
A = randi(999, 1, 5)
plot(1:5, 1:5, 'o-')
xticks(1:5)
xticklabels(string(A))
1 Commento
Walter Roberson
il 12 Feb 2021
xticklabels() as a function did not exist when the question was originally asked either ;-)
Walter Roberson
il 12 Feb 2021
A = randi(999, 1, 5)
plot(1:5, 1:5, 'o-')
xticks(1:5)
xticklabels(compose('%d',A)) %needs R2016b or later
yticklabels(sprintfc('%d', A)) %undocumented
0 Commenti
Vedere anche
Categorie
Scopri di più su Characters and Strings in Help Center e File Exchange
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!