Assigning alphabets to a range of numbers.

3 visualizzazioni (ultimi 30 giorni)
Daniyal Ali
Daniyal Ali il 5 Ott 2016
I have an array of random numbers. I want to assign alphabets to a range of numbers. For example 0-20 should be assigned letter A and so on. Kindly help me how to do this.

Risposte (2)

Walter Roberson
Walter Roberson il 5 Ott 2016
mask = A >= 0 & A <= 20;
result(mask) = 'A' ;

Guillaume
Guillaume il 5 Ott 2016
Modificato: Guillaume il 5 Ott 2016
Your question is really not clear. Possibly:
v = randi([0 20*26-1], 1, 20) %vector of random number
bins = 0:20:20*26; %[0-19] is A, [20-39] is B, etc. the bins don't have to be uniform but they have to be continuous
out = char(discretize(v, bins) + 'A' - 1)
  2 Commenti
Daniyal Ali
Daniyal Ali il 5 Ott 2016
Modificato: Daniyal Ali il 5 Ott 2016
Kindly see the picture for Clarification. Thanks.
Walter Roberson
Walter Roberson il 5 Ott 2016
letter(i) = 'A';
You cannot store letters and numeric values in the same numeric (or character) array.

Accedi per commentare.

Categorie

Scopri di più su Creating and Concatenating Matrices 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