Generation of an Odd numbers only
Afficher commentaires plus anciens
Hello every one I would like to generate a series of random odd numbers with in a specific range for example the range from 1 to 20 the odd number for example 1,3,5,7,9,11,13,15,17,19
Réponse acceptée
Plus de réponses (6)
Sameh elmedawi
le 15 Mar 2022
2 votes
a = 1:2:2*n
How about?
(randi(10, 1, serieslength) - 1) * 2 + 1; %replace serieslength by actual length of series.
That is generate random integers between 0 and 9, multiply by 2 and add 1.
2 commentaires
aya
le 12 Oct 2014
It generates odd numbers between 1 and 19. It's not particularly hard to figure out how to do it for other ranges
halfrange = (maxrange - minrange) / 2; %replace max and min by actual values, values must be odd.
(randi(halfrange, 1, serieslength) - 1) * 2 + minrange;
Noor elhamed
le 28 Avr 2017
0 votes
How to write the code using user defined function?
Gorret Komuhendo
le 8 Fév 2021
0 votes
How do I find the MATLAB command which generate the following lists 1. The odd number 1,3,...99 2. The numbers 10,20,30,...120? Can you help me please
1 commentaire
Image Analyst
le 5 Fév 2022
v1 = 1 : 2 : 99
v2 = 10 : 10 : 120
Chathurni Ratwatte
le 17 Mai 2021
0 votes
Create the vector consisting of the whole odd numbers between 15 and 27
1 commentaire
Walter Roberson
le 5 Fév 2022
[17 19 21 23 25]
FAISAL
le 9 Avr 2023
0 votes
Create a scalar of an odd number
1 commentaire
for K = 1 : 5
scalar = randi([0 65535]) * 2 + 1
end
Catégories
En savoir plus sur Structures dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!