# How to add a +1 to some of the numbers in a matrix

10 views (last 30 days)
polo Mahmoud on 25 Oct 2019
Commented: Adam on 25 Oct 2019
Hi
i have a matrix:
A = [1 2 3 4 5 6 7 8 9 10 11 12
7 8 9 10 11 12 13 14 15 16 17 18
13 14 15 16 17 18 19 20 21 22 23 24];
i want:
A = [1 2 3 4 5 6 7 8 9 10 11 12
7 8 9 10 11 12+1 13+1 14+1 15+1 16+1 17+1 18+1
13+1 14+1 15+1 16+1 17+1 18+1 19+1 20+1 21+1 22+1 23+1 24+1];
and then:
A = [1 2 3 4 5 6 7 8 9 10 11 12
7 8 9 10 11 13 14 15 16 17 18 19+1
14+1 15+1 16+1 17+1 18+1 19+1 20+1 21+1 22+1 23+1 24+1 25+1];
my a loop or something ?
What is the logic behind it? If there is none then you can just hard-code the maths as in Walter's answer.

Walter Roberson on 25 Oct 2019
A(2,6:end) = A(2,6:end) + 1;
A(2,end) = A(2,end) + 1; A(3,:) = A(3,:) + 1;

### Categories

Find more on Matrix Indexing in Help Center and File Exchange

R2019a

### Community Treasure Hunt

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

Start Hunting!

Translated by