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

3 次查看(过去 30 天)
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 ?
  1 个评论
Adam
Adam 2019-10-25
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
Walter Roberson 2019-10-25
A(2,6:end) = A(2,6:end) + 1;
A(2,end) = A(2,end) + 1; A(3,:) = A(3,:) + 1;

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 MATLAB 的更多信息

产品


版本

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by