Ask Your Question
0

Set multiple rows and single column at the same time in Matrix

asked 2017-05-24 10:30:41 -0600

alexMm1 gravatar image

Hi,

i'd like to know how to set multiple rows and single column at the same time in Matrix.

Ex:

Mat my_matrix = Mat::zeros(100, 4, CV_32S);

suppose that I want to set:

  • rows 0-24 column 1 as 1;
  • rows 25-49 column 2 as 1;
  • rows 50-74 column 3 as 1;
  • rows 75-99 column 4 as 1;
edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
1

answered 2017-05-24 11:11:18 -0600

LBerger gravatar image

use setTo and range :

my_matrix(Range(0,25),Range(0,1)).setTo(1);
my_matrix(Range(25,49),Range(1,2)).setTo(1);
my_matrix(Range(50,75),Range(2,3)).setTo(1);
my_matrix(Range(75,100),Range(3,4).setTo(1);

first is column is index 0

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2017-05-24 10:30:41 -0600

Seen: 377 times

Last updated: May 24 '17