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
- :
- Is there a way to extract a specific range of rows...

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

09-24-2016
05:06 PM

09-24-2016
05:06 PM

In Matlab, when I plan to extract a submatrix from a large matrix in the following situation:

Say I want to extract row and column 1 and 4 from K, I can create an index matrix and do this:

idx = [4 1; 1 2; 2 3; 3 5];

k = K(idx(1,,idx(1,);

But in Mathcad, the built in function submatrix can only extract continuous row and column ranges.

Is there a way to let Mathcad do the same job as in Matlab?

Best

Shawn

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

09-26-2016
08:44 PM

15 REPLIES 15

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

09-24-2016
05:40 PM

09-24-2016
05:40 PM

Re: Is there a way to extract a specific range of rows and columns from a matrix?

That is not supported as a built in function. You can program it though.

Luc

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

09-26-2016
09:55 AM

09-26-2016
09:55 AM

Re: Is there a way to extract a specific range of rows and columns from a matrix?

This discussion might help...

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

09-26-2016
10:33 AM

09-26-2016
10:33 AM

Re: Is there a way to extract a specific range of rows and columns from a matrix?

Say I want to extract row and column 1 and 4 from K,

You are not just looking for the extraction of a single matrix element, or are you?

Or do you really mean what you write - extracting the full first and fourth column and also the first and fourth row. This would mean that in your example you want to extract 16 values and four of them would be extracted twice. If that is what you are after, you would have to tell us in which way you would like the 16 (or 12) value being arranged - which data structure.

In case you are looking for a way to extract a couple of matrix elements whose indices are given by a matrix "idx" and collect those elements in a vector, the following two methods should help. Otherwise you would have to come back and specify more detailed what kind of result you are expecting.

BTW, the value 5 in your idx matrix seems to be wrong anyway, even if you set ORIGIN to 1.

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

09-26-2016
05:17 PM

09-26-2016
05:17 PM

Re: Is there a way to extract a specific range of rows and columns from a matrix?

Werner Exinger wrote:

Say I want to extract row and column 1 and 4 from K,

You are not just looking for the extraction of a single matrix element, or are you?

Or do you really mean what you write - extracting the full first and fourth column and also the first and fourth row. This would mean that in your example you want to extract 16 values and four of them would be extracted twice. If that is what you are after, you would have to tell us in which way you would like the 16 (or 12) value being arranged - which data structure.

In case you are looking for a way to extract a couple of matrix elements whose indices are given by a matrix "idx" and collect those elements in a vector, the following two methods should help. Otherwise you would have to come back and specify more detailed what kind of result you are expecting.

BTW, the value 5 in your idx matrix seems to be wrong anyway, even if you set ORIGIN to 1.

5 would be wrong as an index into K as given; however, the example he gives is the Cartesian product of the first row of idx (that is, combinations of 4 and 1), so Matlab will return a 2x2 array of those elements. I've got a few functions that will do vaguely what he wants ... I'll dig them out tomorrow when I've got access to the PC I've got them on.I

A Proper indexing system would be so helpful in cases like this. :-(

Stuart

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

09-26-2016
05:26 PM

09-26-2016
05:26 PM

Re: Is there a way to extract a specific range of rows and columns from a matrix?

Thank you, Stuart.

I posted a similar question before and I remember you answered me on that.

I really appreciate that.

For this homework, I used Matlab to assemble the matrix and it is pretty handy that in Mathcad Prime I can paste the matlab code to demonstrate the process.

Sorry that I lost the function you gave me last time, I changed my computer but I have created a folder in One Drive so that I can always keep the helps from community back up.

I would agree on that Matlab is more flexible in terms of programming, but this semester after my professor pushes the request for units, I found Mathcad really powerful.

Luckily I am not doing Finite Element in Mathcad so that I don't have to assembly a lot.

Thank you guys so much for sparing your time helping the community grow!

Best

Shawn

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

09-26-2016
05:39 PM

09-26-2016
05:39 PM

Re: Is there a way to extract a specific range of rows and columns from a matrix?

Hi, Werner,

Sorry I truncate the original problem that results in some confusion.

The original one is this:

Thus there are 10 DOFs.

With Matlab, I can do this to assemble the matrix:

k = @(L,EI) [12 -12 6*L 6*L;

-12 12 -6*L -6*L;

6*L -6*L 4*L^2 2*L^2;

6*L -6*L 2*L^2 4*L^2]*EI/L^3; % Beam Local Stiffness Matrix

k1 = k(1/4,1); % beam local stiffness matrice

% Assume EI=1, L=1/4;

K = zeros(10,10); % In total there are 10 DOFs

idxc = [4 1 9 6;

1 2 6 7;

2 3 7 8;

3 5 8 10];

% Index for beam elemental DOFs

for i = 1:4 % Assemble global beam stiffness matrix

K(idxc(i,,idxc(i,) = K(idxc(i,,idxc(i,) + k1;

end

Ktt = K(1:5,1:5) - (K(6:10,1:5))'*(K(6:10,6:10))^-1*K(6:10,1:5);

%Stiffness Condensation

Ktt = Ktt(1:3,1:3); % Subtract Boundary Conditions & Rotational DOFs

Here idxc stores all the 4 DOFs for each element, with the DOFs not continuous labeled.

In Mathcad, however, the built in function submatrix cannot work in this way.

Hope this clarify the problem.

Best

Shawn

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

09-26-2016
07:32 PM

09-26-2016
07:32 PM

Re: Is there a way to extract a specific range of rows and columns from a matrix?

> Hope this clarify the problem.

Unfortunately not.

Instead of addressing the obviously wrong index number 5 in your post and instead of simply typing in in Mathcad Prime the result you expect given the very example you gave in your last post to show what you are looking for, you again elaborate on what you could and would do in Matlab, introduce new examples which look like they have not much to do with the one you originally gave and introduce something called DOF (what the hell is a DOF?). Why do you think this would clarify anything?

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

09-26-2016
07:49 PM

09-26-2016
07:49 PM

Re: Is there a way to extract a specific range of rows and columns from a matrix?

Sorry for the confusion. Hope this one might work...

Best

Shawn

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

09-26-2016
07:56 PM

09-26-2016
07:56 PM

Re: Is there a way to extract a specific range of rows and columns from a matrix?

Ah, so you think he is looking for something like this?

Top Tags