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 manipulation question

Subject: matrix manipulation question

From: antonio ferreira

Date: 18 Nov, 2010 15:11:04

Message: 1 of 4

Hi all.
I have two simple matrix a=[1 2;3 4; 5 6; 7 8] and b=[1 10; 5 6; 8 9; 10 10]. I need to create two sub-matrix until the first 5 in the first column and I am not being able to do this. The problem for me is that the number 5 changes from place in matrix a and b. Basically the result should be a sub-matrix c= [1 2;3 4; 5 6] and a submatrix d=[1 10; 5 6]. Could anyone give me a help please?Regards

Subject: matrix manipulation question

From: Sean de

Date: 18 Nov, 2010 15:26:03

Message: 2 of 4

"antonio ferreira" <edgar.acferreira@gmail.com> wrote in message <ic3fm8$qip$1@fred.mathworks.com>...
> Hi all.
> I have two simple matrix a=[1 2;3 4; 5 6; 7 8] and b=[1 10; 5 6; 8 9; 10 10]. I need to create two sub-matrix until the first 5 in the first column and I am not being able to do this. The problem for me is that the number 5 changes from place in matrix a and b. Basically the result should be a sub-matrix c= [1 2;3 4; 5 6] and a submatrix d=[1 10; 5 6]. Could anyone give me a help please?Regards

Like this:
c = a(1:find(a(:,1)==5),:)
?

Subject: matrix manipulation question

From: antonio ferreira

Date: 18 Nov, 2010 15:33:04

Message: 3 of 4

"Sean de " <sean.dewolski@nospamplease.umit.maine.edu> wrote in message <ic3gia$3qe$1@fred.mathworks.com>...
> "antonio ferreira" <edgar.acferreira@gmail.com> wrote in message <ic3fm8$qip$1@fred.mathworks.com>...
> > Hi all.
> > I have two simple matrix a=[1 2;3 4; 5 6; 7 8] and b=[1 10; 5 6; 8 9; 10 10]. I need to create two sub-matrix until the first 5 in the first column and I am not being able to do this. The problem for me is that the number 5 changes from place in matrix a and b. Basically the result should be a sub-matrix c= [1 2;3 4; 5 6] and a submatrix d=[1 10; 5 6]. Could anyone give me a help please?Regards
>
> Like this:
> c = a(1:find(a(:,1)==5),:)
> ?

Exactly.Many thanks

Subject: matrix manipulation question

From: Sean de

Date: 18 Nov, 2010 15:48:03

Message: 4 of 4

"antonio ferreira" <edgar.acferreira@gmail.com> wrote in message <ic3gvg$1h0$1@fred.mathworks.com>...
> "Sean de " <sean.dewolski@nospamplease.umit.maine.edu> wrote in message <ic3gia$3qe$1@fred.mathworks.com>...
> > "antonio ferreira" <edgar.acferreira@gmail.com> wrote in message <ic3fm8$qip$1@fred.mathworks.com>...
> > > Hi all.
> > > I have two simple matrix a=[1 2;3 4; 5 6; 7 8] and b=[1 10; 5 6; 8 9; 10 10]. I need to create two sub-matrix until the first 5 in the first column and I am not being able to do this. The problem for me is that the number 5 changes from place in matrix a and b. Basically the result should be a sub-matrix c= [1 2;3 4; 5 6] and a submatrix d=[1 10; 5 6]. Could anyone give me a help please?Regards
> >
> > Like this:
> > c = a(1:find(a(:,1)==5),:)
> > ?
>
> Exactly.Many thanks

You probably want the 'first' argument in find coupled with 1 returned index; in case there are multiple 5s.
c = a(1:find(a(:,1)==5,1,'first'),:)

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