MATLAB: Subtracting matrix subsets by specific rows

后端 未结 5 1764
刺人心
刺人心 2020-12-03 19:22

Here is an example of a subset of the matrix I would like to use:

1 3 5

2 3 6

1 1 1

3 5 4

5 5 5

8 8 0

5条回答
  •  天涯浪人
    2020-12-03 19:56

    You can do it using just indexing:

    a(:) = a(:) - a(3*floor((0:numel(a)-1)/3)+1).';
    

    Of course, the 3 above can be replaced by any other number. It works even if that number doesn't divide the number of rows.

提交回复
热议问题