Get Help

Turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

- Community
- :
- PTC Mathcad
- :
- PTC Mathcad
- :
- stack two matrices depending on a third matrix

Options

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

Highlighted

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

05-03-2019
02:50 PM

05-03-2019
02:50 PM

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.

Solved! Go to Solution.

Labels:

1 ACCEPTED SOLUTION

Accepted Solutions

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

05-03-2019
05:00 PM

05-03-2019
05:00 PM

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).

See attached MC15 file

5 REPLIES 5

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

05-03-2019
04:31 PM

05-03-2019
04:31 PM

Re: stack two matrices depending on a third matrix

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?

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

05-03-2019
05:00 PM

05-03-2019
05:00 PM

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).

See attached MC15 file

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

05-03-2019
05:56 PM

05-03-2019
05:56 PM

Re: stack two matrices depending on a third matrix

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

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

05-03-2019
06:03 PM

05-03-2019
06:03 PM

Re: stack two matrices depending on a third matrix

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

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

05-03-2019
06:30 PM

05-03-2019
06:30 PM

Re: stack two matrices depending on a third matrix

Yes sir, thanks!

Top Tags