The Math Forum

Search All of the Math Forum:

Views expressed in these public forums are not endorsed by NCTM or The Math Forum.

Math Forum » Discussions » Software » comp.soft-sys.matlab

Notice: We are no longer accepting new posts, but the forums will continue to be readable.

Topic: Adding rows in a matrix based on certain criteria
Replies: 2   Last Post: Feb 7, 2013 9:58 AM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]
Barry Shaw

Posts: 32
Registered: 2/16/12
Re: Adding rows in a matrix based on certain criteria
Posted: Feb 7, 2013 9:58 AM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

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);
matrix(i,3) =nan(1); % What do you want to do if cols 1 and 2 don't equal 1?

"Kumar" wrote in message <kf07gs$f2u$>...
> 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 1-20 and elements in colum 2 varies from 1-10. the size of the matrix is m by 3.

Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© The Math Forum at NCTM 1994-2018. All Rights Reserved.