Thread Subject: how to copy a submatrix fro ma matrix

Subject: how to copy a submatrix fro ma matrix

From: Kishore

Date: 3 Nov, 2009 23:36:05

Message: 1 of 6

hello,

I would want to know if there is any command by which i can copy a sub matrix from a matrix.
What i mean is ,

A = [ 1 2 3 4 5 6;
          3 4 4 5 6 7;
          1.0e-2 1.2e-2 1.3e-2...
          1 2 3 4 5 5]

In the above matrix, i need to copy all elements which are greater than 1,to some matrix,( i.e i do no want the row 1.0e-2.....

This can ofcourse be done in a loop,but is there any command which simplifies the process?

I used bsxfun() ,but it doesnt seem to have this feature.


Thanks

Subject: how to copy a submatrix fro ma matrix

From: ade77

Date: 4 Nov, 2009 00:03:04

Message: 2 of 6

type doc find. or help find.
the 'find' function will return the indicies of the elements or rows that meet your conditions.
Then pass the indicies back to your sub array.
 "Kishore " <kishore3385@yahoo.co.in> wrote in message <hcqep5$f8g$1@fred.mathworks.com>...
> hello,
>
> I would want to know if there is any command by which i can copy a sub matrix from a matrix.
> What i mean is ,
>
> A = [ 1 2 3 4 5 6;
> 3 4 4 5 6 7;
> 1.0e-2 1.2e-2 1.3e-2...
> 1 2 3 4 5 5]
>
> In the above matrix, i need to copy all elements which are greater than 1,to some matrix,( i.e i do no want the row 1.0e-2.....
>
> This can ofcourse be done in a loop,but is there any command which simplifies the process?
>
> I used bsxfun() ,but it doesnt seem to have this feature.
>
>
> Thanks

Subject: how to copy a submatrix fro ma matrix

From: dpb

Date: 4 Nov, 2009 00:23:59

Message: 3 of 6

ade77 wrote:
...[top posting repaired...please don't do that]...
> "Kishore " <kishore3385@yahoo.co.in> wrote in message <hcqep5$f8g$1@fred.mathworks.com>...
...
>> I would want to know if there is any command by which i can copy a
>> sub matrix from a matrix.
...
>>
>> In the above matrix, i need to copy all elements which are greater
>> than 1,to some matrix,( i.e i do no want the row 1.0e-2.....
>>
>> This can ofcourse be done in a loop,but is there any command
>> which simplifies the process? >>
>> I used bsxfun() ,but it doesnt seem to have this feature.
>>
...
 > type doc find. or help find.
 > the 'find' function will return the indicies of the elements or rows
  > that meet your conditions.
 > Then pass the indicies back to your sub array.

Better yet, look up and read about

"logical addressing"

B=A(A>1);

Note however, your example matrix and your description of what you want
aren't quite consonant--saving the elements >1 will eliminate at least a
couple of entries in A that are identically one, not just the row w/
values <1.

If that's what you want precisely, for the sample A you would need

B=A(A>=1);

Also note that there will be a question to decide on what the shape of
the resultant will be--the above will return a column vector which you
can reshape() as desired if necessary.

--

Subject: how to copy a submatrix fro ma matrix

From: ImageAnalyst

Date: 4 Nov, 2009 03:25:08

Message: 4 of 6

Here's a variant on what the others offered. Like they said, your
request is somewhat ambigous.

A = [ 1 2 3 4 5 6; ...
       3 4 4 5 6 7; ...
       1.0e-2 1.2e-2 1.3e-2 1.0e-2 1.2e-2 1.3e-2;...
       1 2 3 4 5 5]
B = zeros(size(A))
keeperIndexes = A>1
B(keeperIndexes) = A(keeperIndexes)

Subject: how to copy a submatrix fro ma matrix

From: dpb

Date: 4 Nov, 2009 15:06:39

Message: 5 of 6

ImageAnalyst wrote:
> Here's a variant on what the others offered. ...

or yet another...

 > A(A<1)=[]
A =
      1 3 4 2 4 4
 >

:)

--

Subject: how to copy a submatrix fro ma matrix

From: Kishore

Date: 5 Nov, 2009 02:52:02

Message: 6 of 6

thanks everybody...

Tags for this Thread

Everyone's Tags:

Add a New Tag:

Separated by commas
Ex.: root locus, bode

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.

Tag Activity for This Thread
Tag Applied By Date/Time
copy submatrix Kishore 3 Nov, 2009 18:39:05
rssFeed for this Thread
 

MATLAB Central Terms of Use

NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Terms prior to use.

Contact us at files@mathworks.com