Retain all initial even value elements, add all odd values with 1
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Using random number generator, generate ten integer values in the form of 1-D array. Store it in a variable named A2Q10. How to retain all initial even value elements, add all odd values with 1? Now I know A2Q10 = randi([1 10],1,10) is to generate. But how to form a new 1-D array to only add 1 to odd value elements from the generated 1-D array. Please help me!
0 Kommentare
Antworten (1)
KSSV
am 23 Nov. 2021
Hint: Read about mod. If mod(x,2) is 1 then x is odd.
mod(4,2) % even number
mod(5,2) % odd number
Siehe auch
Kategorien
Mehr zu Matrices and Arrays finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!