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 (최근 30일)
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);

채택된 답변

Roger Stafford
Roger Stafford 2014년 3월 5일
t = mod(A,2)==1;
A(t) = A(t) + 1;

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Linear Algebra에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by