Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Matrix partition and submatrix extraction

Subject: Matrix partition and submatrix extraction

From: Simon Mouer

Date: 4 Sep, 2004 10:52:47

Message: 1 of 14

I have a simple linear matrix equation:

P = K U

which I have to partition into:

P1 K11 K12 U1
P2 K21 K22 U2

I am looking for a simple way in MATLAB to do the partition (K is a
square matrix) and extract the submatrices into four seperate
matrices which are components of other equations. The partition point
is known.

Currently I create matrix K in MATLAB, then export it to Microsoft
Excel to do the partition, then put these submatrices (as seperate
matrices) back into MATLAB.

Subject: Matrix partition and submatrix extraction

From: Jeje007

Date: 5 Sep, 2004 17:49:37

Message: 2 of 14

Simon Mouer wrote:
>
>
> I have a simple linear matrix equation:
>
> P = K U
>
> which I have to partition into:
>
> P1 K11 K12 U1
> P2 K21 K22 U2
>
> I am looking for a simple way in MATLAB to do the partition (K is a
> square matrix) and extract the submatrices into four seperate
> matrices which are components of other equations. The partition
> point
> is known.
>
> Currently I create matrix K in MATLAB, then export it to Microsoft
> Excel to do the partition, then put these submatrices (as seperate
> matrices) back into MATLAB.

Hello,

If I understand ur problem, the best solution
in Matlab to do that is :

DimMat = size(K);
Indexs = floor(DimMat / 2);
K11 = K(1:Indexs(1),1:Indexs(2));
K12 = K(1:Indexs(1),(Indexs(2)+1):end);
K21 = K((Indexs(1)+1):end,1:Indexs(2));
K22 = K((Indexs(1)+1):end,(Indexs(2)+1):end);

And u can do the same with U and P matrix ...

Good luck, and have a good day
Jeje

Subject: Matrix partition and submatrix extraction

From: Simon

Date: 5 Sep, 2004 19:11:46

Message: 3 of 14

Jeje007 wrote:
>
>
> Simon Mouer wrote:
>>
>>
>> I have a simple linear matrix equation:
>>
>> P = K U
>>
>> which I have to partition into:
>>
>> P1 K11 K12 U1
>> P2 K21 K22 U2
>>
>> I am looking for a simple way in MATLAB to do the partition (K
is
> a
>> square matrix) and extract the submatrices into four seperate
>> matrices which are components of other equations. The partition
>> point
>> is known.
>>
>> Currently I create matrix K in MATLAB, then export it to
> Microsoft
>> Excel to do the partition, then put these submatrices (as
> seperate
>> matrices) back into MATLAB.
>
> Hello,
>
> If I understand ur problem, the best solution
> in Matlab to do that is :
>
> DimMat = size(K);
> Indexs = floor(DimMat / 2);
> K11 = K(1:Indexs(1),1:Indexs(2));
> K12 = K(1:Indexs(1),(Indexs(2)+1):end);
> K21 = K((Indexs(1)+1):end,1:Indexs(2));
> K22 = K((Indexs(1)+1):end,(Indexs(2)+1):end);
>
> And u can do the same with U and P matrix ...
>
> Good luck, and have a good day
> Jeje

Thanks for the solution.

Subject: Matrix partition and submatrix extraction

From: Simon Mouer

Date: 6 Sep, 2004 10:00:52

Message: 4 of 14

Jeje007 wrote:
>
>
> Simon Mouer wrote:
>>
>>
>> I have a simple linear matrix equation:
>>
>> P = K U
>>
>> which I have to partition into:
>>
>> P1 K11 K12 U1
>> P2 K21 K22 U2
>>
>> I am looking for a simple way in MATLAB to do the partition (K
is
> a
>> square matrix) and extract the submatrices into four seperate
>> matrices which are components of other equations. The partition
>> point
>> is known.
>>
>> Currently I create matrix K in MATLAB, then export it to
> Microsoft
>> Excel to do the partition, then put these submatrices (as
> seperate
>> matrices) back into MATLAB.
>
> Hello,
>
> If I understand ur problem, the best solution
> in Matlab to do that is :
>
> DimMat = size(K);
> Indexs = floor(DimMat / 2);
> K11 = K(1:Indexs(1),1:Indexs(2));
> K12 = K(1:Indexs(1),(Indexs(2)+1):end);
> K21 = K((Indexs(1)+1):end,1:Indexs(2));
> K22 = K((Indexs(1)+1):end,(Indexs(2)+1):end);
>
> And u can do the same with U and P matrix ...
>
> Good luck, and have a good day
> Jeje

I thanked you too soon . I tried your solution, but I got the
following error message:

??? Undefined function or variable 'Indexs'.

In fact, I can't seem to extract any element of a matrix. It is hard
to believe what appears to be a powerful matrix manipulator doesn't
allow easy address and manipulation of element or ranges of elements.

Any further advice? I am running version 5.03 (R11).

Is it me, or is it MatLab?

Subject: Matrix partition and submatrix extraction

From: Michael Wild

Date: 6 Sep, 2004 10:23:52

Message: 5 of 14

Tell me, have you ever read any doc on matrix manipulation???

A = magic(10); % some square matrix
i=5; % partition indices: row 5, column 5
j=5;
A11 = A(1:i,1:j); % extract submatrices
A12 = A(1:i,j+1:end);
A21 = A(i+1:end,1:j);
A22 = A(i+1:end,j+1:end);

Michael

"Simon Mouer" <dr_mouer@yahoo.com> schrieb im Newsbeitrag
news:eee8b3d.-1@webx.raydaftYaTP...
> I have a simple linear matrix equation:
>
> P = K U
>
> which I have to partition into:
>
> P1 K11 K12 U1
> P2 K21 K22 U2
>
> I am looking for a simple way in MATLAB to do the partition (K is a
> square matrix) and extract the submatrices into four seperate
> matrices which are components of other equations. The partition point
> is known.
>
> Currently I create matrix K in MATLAB, then export it to Microsoft
> Excel to do the partition, then put these submatrices (as seperate
> matrices) back into MATLAB.

Subject: Matrix partition and submatrix extraction

From: Simon Mouer

Date: 6 Sep, 2004 23:07:58

Message: 6 of 14

Michael,
Thanks - your solution works.

To answer your question if I have ever read any documentation - I
assume you mean on MatLab --
The answer is - very little. I am using a colleagues copy of MatLab
for evaluation, and find very little in the way of adequate
documentation or examples.

I teach Matrix Structural Analysis at a local university, so you
would think MatLab would be a Godsend. But I am not quite ready to
commit to purchase my own copy (or require my students to do so)
until I can assure myself it is at least an adequate, economical, and
user-friendly solution for both me and my students. I want to give
them programmed solutions that they can understand, modify, and
extend.

For example, I like the fact that MatLab interfaces with Excel, but
getting that link to work was a real pain. While the MatLab matrix
algebra statements are intuitive, other Matlab statements don't
appear to be very intuitive, nor (in my opinion) well explained. So
far, the best help I have received is from the user community.

The relative intuitiveness (to me) of MatLab versus Fortran may be
because I cut my teeth on FORTRAN back in the 60's. For that matter,
Visual Basic doesn't seem to be as intuitive as Fortran either -- so
that may be just me and my first programming language.

If you know a cheap source of MatLab documentation and examples, I
would appreciate it greatly.

Thanks again for the help.
Simon

Michael Wild wrote:
>
>
> Tell me, have you ever read any doc on matrix manipulation???
>
> A = magic(10); % some square matrix
> i=5; % partition indices: row 5, column 5
> j=5;
> A11 = A(1:i,1:j); % extract submatrices
> A12 = A(1:i,j+1:end);
> A21 = A(i+1:end,1:j);
> A22 = A(i+1:end,j+1:end);
>
> Michael
>
> "Simon Mouer" <dr_mouer@yahoo.com> schrieb im Newsbeitrag
> news:eee8b3d.-1@webx.raydaftYaTP...
>> I have a simple linear matrix equation:
>>
>> P = K U
>>
>> which I have to partition into:
>>
>> P1 K11 K12 U1
>> P2 K21 K22 U2
>>
>> I am looking for a simple way in MATLAB to do the partition (K
is
> a
>> square matrix) and extract the submatrices into four seperate
>> matrices which are components of other equations. The partition
> point
>> is known.
>>
>> Currently I create matrix K in MATLAB, then export it to
> Microsoft
>> Excel to do the partition, then put these submatrices (as
> seperate
>> matrices) back into MATLAB.
>
>
>

Subject: Matrix partition and submatrix extraction

From: Dan Hensley

Date: 7 Sep, 2004 04:04:20

Message: 7 of 14

On Mon, 06 Sep 2004 23:07:58 -0400, Simon Mouer wrote:

> I teach Matrix Structural Analysis at a local university, so you
> would think MatLab would be a Godsend. But I am not quite ready to
> commit to purchase my own copy (or require my students to do so)
> until I can assure myself it is at least an adequate, economical, and
> user-friendly solution for both me and my students. I want to give
> them programmed solutions that they can understand, modify, and
> extend.

You might also look at Octave if you want a much cheaper (as in free)
alternative.

> If you know a cheap source of MatLab documentation and examples, I
> would appreciate it greatly.

I think the Matlab documentation in general is quite good. Just start
with 'doc' at the prompt, and go to Getting Started.

Dan



>
> Thanks again for the help.
> Simon
>
> Michael Wild wrote:
>>
>>
>> Tell me, have you ever read any doc on matrix manipulation???
>>
>> A = magic(10); % some square matrix
>> i=5; % partition indices: row 5, column 5
>> j=5;
>> A11 = A(1:i,1:j); % extract submatrices
>> A12 = A(1:i,j+1:end);
>> A21 = A(i+1:end,1:j);
>> A22 = A(i+1:end,j+1:end);
>>
>> Michael
>>
>> "Simon Mouer" <dr_mouer@yahoo.com> schrieb im Newsbeitrag
>> news:eee8b3d.-1@webx.raydaftYaTP...
>>> I have a simple linear matrix equation:
>>>
>>> P = K U
>>>
>>> which I have to partition into:
>>>
>>> P1 K11 K12 U1
>>> P2 K21 K22 U2
>>>
>>> I am looking for a simple way in MATLAB to do the partition (K
> is
>> a
>>> square matrix) and extract the submatrices into four seperate
>>> matrices which are components of other equations. The partition
>> point
>>> is known.
>>>
>>> Currently I create matrix K in MATLAB, then export it to
>> Microsoft
>>> Excel to do the partition, then put these submatrices (as
>> seperate
>>> matrices) back into MATLAB.
>>
>>
>>

Subject: Matrix partition and submatrix extraction

From: Michael Wild

Date: 7 Sep, 2004 02:33:06

Message: 8 of 14

I agree with Dan, the html-doc is very good and extensive when compared to
other programming languages. And as to the comparision with Fortran: Have
you ever compared to F90/95? The syntax in the newer Fortran versions is
very similar to that in Matlab.
In my experience one has to learn only a few things about the matlab
language and is then able to easily and very rapidly solve complex problems.
Very much faster than with C++ or VisualBasic for example. Most of all:
there's less code to write. The api is huge and extensible with toolboxes.
And besides: why connect to Excel? Matlab does everything and more than
Excel!

If you are teaching students, let them buy it. They'll come love it (you
see, I'm a student myself), and with not even $100 for a student license I
think it's more than just affordable.

Michael

"Dan Hensley" <dan@somewhere.net> schrieb im Newsbeitrag
news:pan.2004.09.07.04.04.18.674334@somewhere.net...
> On Mon, 06 Sep 2004 23:07:58 -0400, Simon Mouer wrote:
>
> > I teach Matrix Structural Analysis at a local university, so you
> > would think MatLab would be a Godsend. But I am not quite ready to
> > commit to purchase my own copy (or require my students to do so)
> > until I can assure myself it is at least an adequate, economical, and
> > user-friendly solution for both me and my students. I want to give
> > them programmed solutions that they can understand, modify, and
> > extend.
>
> You might also look at Octave if you want a much cheaper (as in free)
> alternative.
>
> > If you know a cheap source of MatLab documentation and examples, I
> > would appreciate it greatly.
>
> I think the Matlab documentation in general is quite good. Just start
> with 'doc' at the prompt, and go to Getting Started.
>
> Dan
>
>
>
> >
> > Thanks again for the help.
> > Simon
> >
> > Michael Wild wrote:
> >>
> >>
> >> Tell me, have you ever read any doc on matrix manipulation???
> >>
> >> A = magic(10); % some square matrix
> >> i=5; % partition indices: row 5, column 5
> >> j=5;
> >> A11 = A(1:i,1:j); % extract submatrices
> >> A12 = A(1:i,j+1:end);
> >> A21 = A(i+1:end,1:j);
> >> A22 = A(i+1:end,j+1:end);
> >>
> >> Michael
> >>
> >> "Simon Mouer" <dr_mouer@yahoo.com> schrieb im Newsbeitrag
> >> news:eee8b3d.-1@webx.raydaftYaTP...
> >>> I have a simple linear matrix equation:
> >>>
> >>> P = K U
> >>>
> >>> which I have to partition into:
> >>>
> >>> P1 K11 K12 U1
> >>> P2 K21 K22 U2
> >>>
> >>> I am looking for a simple way in MATLAB to do the partition (K
> > is
> >> a
> >>> square matrix) and extract the submatrices into four seperate
> >>> matrices which are components of other equations. The partition
> >> point
> >>> is known.
> >>>
> >>> Currently I create matrix K in MATLAB, then export it to
> >> Microsoft
> >>> Excel to do the partition, then put these submatrices (as
> >> seperate
> >>> matrices) back into MATLAB.
> >>
> >>
> >>
>

Subject: Matrix partition and submatrix extraction

From: beliavsky@aol.com

Date: 7 Sep, 2004 05:41:24

Message: 9 of 14

"Michael Wild" <themiwi@student.ethz.ch> wrote in message news:<AF306DC7E741D147561D494996DAEB87@in.webx.raydaftYaTP>...
> I agree with Dan, the html-doc is very good and extensive when compared to
> other programming languages. And as to the comparision with Fortran: Have
> you ever compared to F90/95? The syntax in the newer Fortran versions is
> very similar to that in Matlab.

True. John Akin has written a translation table between Fortran 90 and
Matlab, available at
http://www.owlnet.rice.edu/~mech517/F90_Overview.html .

The G95 compiler at http://www.g95.org is free for Linux and other
Unix operating systems, the Intel Fortran 95 compiler for Linux is
free for non-commercial use and the student edition for Windows costs
about $30.

> In my experience one has to learn only a few things about the matlab
> language and is then able to easily and very rapidly solve complex problems.
> Very much faster than with C++ or VisualBasic for example. Most of all:
> there's less code to write. The api is huge and extensible with toolboxes.
> And besides: why connect to Excel? Matlab does everything and more than
> Excel!
>
> If you are teaching students, let them buy it. They'll come love it (you
> see, I'm a student myself), and with not even $100 for a student license I
> think it's more than just affordable.

The problem is that in industry, a Matlab license costs almost $2000,
so companies often purchase floating licenses. I don't want to call a
colleague to ask when he'll be done with Matlab or (still worse) to be
asked the same question. Deploying a Matlab application across the
firm is not so easy -- a colleague was recently informed that a Matlab
compiler for Windows costs $20,000!

Subject: Matrix partition and submatrix extraction

From: Michael Wild

Date: 7 Sep, 2004 09:16:37

Message: 10 of 14

Well, yes. Commercial licenses are very expensive. Although I think the
price for the compiler is too high, it's "only" CHF 9500 the last time I
looked it up.
But still I think, that matlab makes learning modern FORTRAN much easier,
gives the students strong focus on algorithmic programming and shows them
what is possible. Stepping back to Excel won't be hard if it is necessary.

Michael


<beliavsky@aol.com> schrieb im Newsbeitrag
news:3064b51d.0409070441.4ab35a3a@posting.google.com...
> "Michael Wild" <themiwi@student.ethz.ch> wrote in message
news:<AF306DC7E741D147561D494996DAEB87@in.webx.raydaftYaTP>...
> > I agree with Dan, the html-doc is very good and extensive when compared
to
> > other programming languages. And as to the comparision with Fortran:
Have
> > you ever compared to F90/95? The syntax in the newer Fortran versions is
> > very similar to that in Matlab.
>
> True. John Akin has written a translation table between Fortran 90 and
> Matlab, available at
> http://www.owlnet.rice.edu/~mech517/F90_Overview.html .
>
> The G95 compiler at http://www.g95.org is free for Linux and other
> Unix operating systems, the Intel Fortran 95 compiler for Linux is
> free for non-commercial use and the student edition for Windows costs
> about $30.
>
> > In my experience one has to learn only a few things about the matlab
> > language and is then able to easily and very rapidly solve complex
problems.
> > Very much faster than with C++ or VisualBasic for example. Most of all:
> > there's less code to write. The api is huge and extensible with
toolboxes.
> > And besides: why connect to Excel? Matlab does everything and more than
> > Excel!
> >
> > If you are teaching students, let them buy it. They'll come love it (you
> > see, I'm a student myself), and with not even $100 for a student license
I
> > think it's more than just affordable.
>
> The problem is that in industry, a Matlab license costs almost $2000,
> so companies often purchase floating licenses. I don't want to call a
> colleague to ask when he'll be done with Matlab or (still worse) to be
> asked the same question. Deploying a Matlab application across the
> firm is not so easy -- a colleague was recently informed that a Matlab
> compiler for Windows costs $20,000!

Subject: Matrix partition and submatrix extraction

From: Simon Mouer

Date: 7 Sep, 2004 09:53:18

Message: 11 of 14

To Michael and all who responded:

Thanks so much for your solutions, comments, references, and links.
They re very helpful and informative. I am slowly getting
"aclimatized" to MatLab.

I started with Excel because it is so standard - on almost anyone's
computer, and generally easy to use. Not really an efficient matrix
manipulator, but it does force students to perform every step of the
operations to achieve a solution. But once they understand the
processes, then Excel becomes constrictive, hence the desire to have
a more efficient manipulator.

I teach in the Philipines, where I retired to, and took up teaching
because being retired tends to be boring. Here, an average student
is lucky to make $100 a month, and even an experienced and well
placed engineer may only make a few hundred a month. So a hundred
dollar program - no big deal in the US or EU - becomes an
insurmountable barrier here.

I haven't started developing a GUI interface, using the Excel
interface for now. But I'll start soon, and sure to be back with more
questions.

While I might harbor some reservations about the suitability of
MatLab for 3rd-world students, the Matlab user community is very
helpful and responsive.

Best regards to all,
Simon

Michael Wild wrote:
>
>
> Well, yes. Commercial licenses are very expensive. Although I think
> the
> price for the compiler is too high, it's "only" CHF 9500 the last
> time I
> looked it up.
> But still I think, that matlab makes learning modern FORTRAN much
> easier,
> gives the students strong focus on algorithmic programming and
> shows them
> what is possible. Stepping back to Excel won't be hard if it is
> necessary.
>
> Michael
>
>
> <beliavsky@aol.com> schrieb im Newsbeitrag
> news:3064b51d.0409070441.4ab35a3a@posting.google.com...
>> "Michael Wild" <themiwi@student.ethz.ch> wrote in message
>
news:<AF306DC7E741D147561D494996DAEB87@in.webx.raydaftYaTP>...
>> > I agree with Dan, the html-doc is very good and extensive
when
> compared
> to
>> > other programming languages. And as to the comparision
with
> Fortran:
> Have
>> > you ever compared to F90/95? The syntax in the newer
Fortran
> versions is
>> > very similar to that in Matlab.
>>
>> True. John Akin has written a translation table between Fortran
> 90 and
>> Matlab, available at
>> <http://www.owlnet.rice.edu/~mech517/F90_Overview.html> .
>>
>> The G95 compiler at <http://www.g95.org>
> s free for Linux and other
>> Unix operating systems, the Intel Fortran 95 compiler for Linux
> is
>> free for non-commercial use and the student edition for Windows
> costs
>> about $30.
>>
>> > In my experience one has to learn only a few things about
the
> matlab
>> > language and is then able to easily and very rapidly solve
> complex
> problems.
>> > Very much faster than with C++ or VisualBasic for example.
Most
> of all:
>> > there's less code to write. The api is huge and extensible
with
> toolboxes.
>> > And besides: why connect to Excel? Matlab does everything
and
> more than
>> > Excel!
>> >
>> > If you are teaching students, let them buy it. They'll
come
> love it (you
>> > see, I'm a student myself), and with not even $100 for a
> student license
> I
>> > think it's more than just affordable.
>>
>> The problem is that in industry, a Matlab license costs almost
> $2000,
>> so companies often purchase floating licenses. I don't want to
> call a
>> colleague to ask when he'll be done with Matlab or (still
worse)
> to be
>> asked the same question. Deploying a Matlab application across
> the
>> firm is not so easy -- a colleague was recently informed that a
> Matlab
>> compiler for Windows costs $20,000!
>
>
>

Subject: Matrix partition and submatrix extraction

From: P

Date: 7 Sep, 2004 13:42:49

Message: 12 of 14

Simon Mouer wrote:
<SNIP thanks ....>
> They re very helpful and informative. I am slowly getting
> "aclimatized" to MatLab.

While your´e at it, try to get "Acklamized" as well. I took the
liberty to post a part of the cssm FAQ (Q9.6) that could be of
interest when talking about array manipulation:

Q9.6: What is Acklamization?
============================

   As contributed by Gautam Sethi
<gautam@nospam.are.berkeley.edu>:

*Acklamize (v):*
     To take any MATLAB code and modify it for the explicit purpose
of
     refining and perfecting. The refinements may be aesthetic in
one
     or more of the following ways: memory use, processing speed or
     sheer elegance in its written form. Also see Acklamizer(n).

*Acklamizer (n):*
     An individual who indulges in the process of acklamization. See
     Acklamize (v).

   Acklamization is named after Peter Acklam, a regular participant
in
comp.soft-sys.matlab and an expert in what is now termed
*acklamization*. Take a look at his web site of "Matlab array
manipulation tips and tricks" at
<http://home.online.no/~pjacklam/matlab/doc/mtt/index.html>.
 
<SNIP>

Subject: Matrix partition and submatrix extraction

From: frequent poster

Date: 7 Sep, 2004 14:36:52

Message: 13 of 14

Simon Mouer wrote:
>
>
<snip, long, log discussion that ended up with how much ML
costs...

Given that you are teaching, why not implement ML-type stuff in C++?
If you use Linux, g++ if FREE and works really well. You can teach
matrix math and have your students make matrix classes that implement
it. In my student experience (FORTRAN etc), the biggest block to
writing matrix code is all those loops you have to write. If your
students are compelled to writing a damn good matrix class, all the
rest is easy. You could even use gnuplot for pictures.

Subject: Matrix partition and submatrix extraction

From: beliavsky@aol.com

Date: 7 Sep, 2004 15:55:42

Message: 14 of 14

"frequent poster" <boozing@every.bar> wrote in message news:<eee8b3d.11@webx.raydaftYaTP>...
> Simon Mouer wrote:
> >
> >
> <snip, long, log discussion that ended up with how much ML
> costs...
>
> Given that you are teaching, why not implement ML-type stuff in C++?
> If you use Linux, g++ if FREE and works really well. You can teach
> matrix math and have your students make matrix classes that implement
> it. In my student experience (FORTRAN etc), the biggest block to
> writing matrix code is all those loops you have to write.

G++ can be used on Windows as well as Linux.

As a student you were probably using Fortran 77 or 66. Fortran 90 and
95 have array operations similar to Matlab. G95 is a free Fortran 95
compiler for Linux (see http://www.g95.org/ ), and the Intel Fortran
compiler for Linux is free for non-commercial use. Unless it's a
programming class, I doubt it's a good use of time to have students
reinvent the wheel in C++.

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us