Hi guys, I have a matrix of 2 columns and 85 rows. The second column contains these numbers: 1, 2, 3, 4, 5 and 6. I want to sum elements of the first column with the condition that the equivalent element from the second column = 1 for example. How can I do that without using a loop? Thanks a lot. Best, Hamza

0 |

12/20/2016 4:57:03 PM

"Hamza Chiheb" wrote in message <o3bnsv$b0m$1@newscl01ah.mathworks.com>... > Hi guys, > > I have a matrix of 2 columns and 85 rows. The second column contains these numbers: 1, 2, 3, 4, 5 and 6. I want to sum elements of the first column with the condition that the equivalent element from the second column = 1 for example. How can I do that without using a loop? > > Thanks a lot. > > Best, > Hamza x = your 85x2 matrix result = sum(x(x(:,2)==1,1)); James Tursa

0 |

12/20/2016 6:17:03 PM

Thanks a lot James!

0 |

12/20/2016 6:32:03 PM