Assigning Alphabet to Different Range of Numbers

3 visualizzazioni (ultimi 30 giorni)
I have the following code.
r = randi([0 5719],1,384); %Generate 384 random numbers between 0-5719.
for i=1:384 if (r(i)>=0 && r(i)<41) r(i)=='A'; end end
I want to assign the following ranges. Numbers 0-40 should get A assigned. So i want to assign the alphabet "A" to r(i) where r(i) lies between 0 to 40. Kindly help.

Risposta accettata

KSSV
KSSV il 5 Ott 2016
clc; clear all ;
r = randi([0 5719],1,384); %Generate 384 random numbers between 0-5719.
rstr = cell(size(r)) ; % initialize cell string
idx = r(r>=0 & r<=40) ; % get positions of random number bw [0,40] ;
% fill rstr at idx's with 'A'
for i = 1:length(idx)
rstr{idx(i)} = 'A';
end

Più risposte (0)

Community Treasure Hunt

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

Start Hunting!

Translated by