cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - You can Bookmark boards, posts or articles that you'd like to access again easily! X

Conditional sum of values in one vector based on another vector

Gaz_Ball
6-Contributor

Conditional sum of values in one vector based on another vector

Hi, wondering if someone can help me out with this one please?

 

Mathcad Prime 7

 

I have a vector [A], which could have any number of rows, each element can be either zero or one, and the origin element is always one.

 

I have another vector [B], which has the same number of rows as [A], and contains data (forces).

 

I would like to create another vector [C], where each element in [C] should equal the corresponding element in [B] if the corresponding element in [A] equals one. If an element in [A] equals zero then that value in [B] gets added to the last element in [C] that related to a one in [A]. That continues until another one appears in [A], and it starts again. Elements in [C] that correspond with zero elements in [A] should equal zero.

 

For example:

Gaz_Ball_0-1665734732899.png

Thanks

ACCEPTED SOLUTION

Accepted Solutions
Werner_E
25-Diamond I
(To:Gaz_Ball)

I guess this function should do the trick

Werner_E_3-1665743432733.png

P6 file attached

 

 

View solution in original post

2 REPLIES 2
Werner_E
25-Diamond I
(To:Gaz_Ball)

I guess this function should do the trick

Werner_E_3-1665743432733.png

P6 file attached

 

 

Gaz_Ball
6-Contributor
(To:Werner_E)

Fantastic! Thank you.

Announcements

Top Tags