Alternative to looping for a matrix

Hi everyone,

Does anyone know of a faster way of doing this? I want to count the number of columns of the matrix B whose rows lie outside the range of minp and maxp. I thought of doing it using count_if but i have no idea of how to implement this for a matrix.

Thanks,
Kate

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
  std::vector<std::vector<double> > B( 3, std::vector<double>(5 ) );
		  std::vector<double> maxp(3);std::vector<double> minp(3);int ss;int ctt;
		  
		B[0][0]=1;B[0][1]=2;B[0][2]=5;B[0][3]=3;B[0][4]=4;
		B[1][0]=2;B[1][1]=4;B[1][2]=2;B[1][3]=3;B[1][4]=4;
		B[2][0]=3;B[2][1]=3;B[2][2]=1;B[2][3]=2;B[2][4]=5;
		
		minp[0]=6;minp[1]=5;minp[2]=1;maxp[0]=8;maxp[1]=8;maxp[2]=2;
		ctt=0;
for (int j=0;j<int(B[0].size());j++){ss=0;
for (int k=0;k<=2;k++){
ss=ss+ (B[k][j]<=minp[k] || B[k][j]>=maxp[k]);
}

if (ss>0){ctt=ctt+1;}
}
Last edited on
Topic archived. No new replies allowed.