Search All of the Math Forum:
Views expressed in these public forums are not endorsed by
NCTM or The Math Forum.



Re: Adding rows in a matrix based on certain criteria
Posted:
Feb 7, 2013 9:58 AM


It would be helpful if you posted what you have attempted and any errors. I'm not sure if I've grasped what you're trying to. Does this help?
m = 5; matrix = [[1 20 3 4 1]' [1 1 10 2 1]']; % for example
for i = 1 : m if matrix(i,1) == 1 & matrix(i,2) == 1 matrix(i,3) = matrix(i,1) + matrix(i,2); else matrix(i,3) =nan(1); % What do you want to do if cols 1 and 2 don't equal 1? end end matrix
"Kumar" wrote in message <kf07gs$f2u$1@newscl01ah.mathworks.com>... > I'm new to Matlab programmin and this may look like a simple question. I have to add rows in matrix based on certain criteria. For example, if the values in column 1 is 1 and values in cloumn 2 is 1, then i have to add elements in colum 3 of all such rows. In the matrix, elemets in column 1 varies from 120 and elements in colum 2 varies from 110. the size of the matrix is m by 3.



