Azzera filtri
Azzera filtri

How can I create a vector that has all of the elements of a random vector, but will add 1 to each of the odd elements?

3 visualizzazioni (ultimi 30 giorni)
I created a row vector of 20 random integers from 0-50 and would now like to create a new vector which has all of the elements of the first vector, but adds one to each of the odd elements. How would I go about this?
>> A=randi([0 50],1,20);

Risposta accettata

Roger Stafford
Roger Stafford il 5 Mar 2014
t = mod(A,2)==1;
A(t) = A(t) + 1;

Più risposte (0)

Categorie

Scopri di più su Random Number Generation 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