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

Community Tip - Have a PTC product question you need answered fast? Chances are someone has asked it before. Learn about the community search. X

stack two matrices depending on a third matrix

IRarch
8-Gravel

stack two matrices depending on a third matrix

I have an initial matrix containing "Yes" and "No". This initial Matrix is named A. A can start with a "Yes" or start with a "No" and the times "Yes" and "No" are in the A Matrix should be unlimited. 

 

In A the "Yes" and "No" do always alternate, they never repeat.

 

Then there are two matrices which are really vectors; B and C.

 

I want to stack these two vectors which might have the same number of columns or might not. For this case A, B, and C always have one row.

 

Recap: A is manually input; B and C are also manually input. Matrix D is generated.

            Matrix D is the generated Matrix which is going to have one row. For columns it will have the sum of the                columns of B and C or simply the number of columns from the A Matrix which should be the same as the              sum of columns of B and C.

 

D’s first element will be the first element of B if A starts with a “Yes”, but it will be the first element of C if A starts with a “No”. Then it will alternate between the elements of B and C.

 

An example with out a program to generate Matrix D is attached.

 

I was thinking of a for function with a stack and an if embedded.  

 

Thanks for anyone's help on this.

ACCEPTED SOLUTION

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

Here is a function which does a bit more than you demanded as the order the elements are interleaved is here fully controlled by vector A (the "Yes" and "No"s don't necessarily have to strictly alternate).

B.png

See attached MC15 file

View solution in original post

5 REPLIES 5
Werner_E
25-Diamond I
(To:IRarch)

1) A "vector" is in Mathcad always and only a column vector (n rows, 1 column). When you write "vector" you seem to be talking of a row vector, a 1 x n matrix. Correct?

 

2) You wrote that you want to "stack" your matrices B and C which would mean to create a matrix with 2 rows. Later you write that D should consist of just 1 row. I guess you don't mean "stack" but rather some kind of "augment". Correct?

 

3) You write that the "yes" and "no"s always alternate. This would lead to two conclusions:

a) Only the first element ("yes" or "no") of vector/matrix A is significant. We don't have to see the rest as we know that they alternate

b) Vectors/matrices B and C must definitely have the same number of elements or one of them has just one element more than the other. Otherwise it would not be possible to interleave the two matrices in a way that there never are two elements of the same matrix joining.

Correct?

 

If all of the above is correct this would mean that there are just two cases to consider.

1) B and C have the same number of elements:

Here we would need to know just the fist element of vector A to determine if the interleaving should begin with B or with C

2) One of the row vectors B and C has 1 element more than the other:

Here we won't need the vector A at all as we must begin the interleaving with the larger vector.

 

Is the above all as you have it in mind?

 

Hello Werner,

 

1) Yes, you are correct. Should've known a vector is always in column form.

 

2) Yes, you are correct, the right term is "augment".

 

3) Yes, the "Yes" and "No"s alternate. And yes, they will have the same amount of elements or one of them just have one element more than the other. In some cases they would have the same amount of elements in some cases one will have only one more than the other. Depends on the necessity of the case.

 

Thanks for making this clear 😉

Werner_E
25-Diamond I
(To:IRarch)

So, would you say the function I posted does what you need?

Yes sir, thanks!

Werner_E
25-Diamond I
(To:IRarch)

Here is a function which does a bit more than you demanded as the order the elements are interleaved is here fully controlled by vector A (the "Yes" and "No"s don't necessarily have to strictly alternate).

B.png

See attached MC15 file

Announcements

Top Tags