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-maximum value

Subject: matrix manipulation-maximum value

From: antonio ferreira

Date: 24 Apr, 2011 17:55:05

Message: 1 of 4

Hi all. I have a very simple matrix A=[0 0.5;1 3;2 4;3 1; 4 0.5;5 7;6 8;7 9;8 10;9 3;10 13].
As you can see the first column values are always growing. My objective is to compute the maximum value in the second column that corresponds to the range 3.5 to 7.2 in the first column. In this case matlab should only consider the sub matrix [4 0.5;5 7;6 8;7 9] and the final result should be 9. Is this possible to do in matlab?Many thanks.

Subject: matrix manipulation-maximum value

From: Roger Stafford

Date: 24 Apr, 2011 18:29:06

Message: 2 of 4

"antonio ferreira" wrote in message <ip1o5p$28p$1@fred.mathworks.com>...
> Hi all. I have a very simple matrix A=[0 0.5;1 3;2 4;3 1; 4 0.5;5 7;6 8;7 9;8 10;9 3;10 13].
> As you can see the first column values are always growing. My objective is to compute the maximum value in the second column that corresponds to the range 3.5 to 7.2 in the first column. In this case matlab should only consider the sub matrix [4 0.5;5 7;6 8;7 9] and the final result should be 9. Is this possible to do in matlab?Many thanks.
- - - - - - - - -
max(A((3.5<=A(:,1))&(A(:,1)<=7.2),2))

Roger Stafford

Subject: matrix manipulation-maximum value

From: dpb

Date: 24 Apr, 2011 18:30:10

Message: 3 of 4

On 4/24/2011 12:55 PM, antonio ferreira wrote:
> Hi all. I have a very simple matrix A=[0 0.5;1 3;2 4;3 1; 4 0.5;5 7;6
> 8;7 9;8 10;9 3;10 13].
> As you can see the first column values are always growing.

...red herring...like the superfluous information in the elementary
mathbook.


My objective
> is to compute the maximum value in the second column that corresponds to
> the range 3.5 to 7.2 in the first column. In this case matlab should
> only consider the sub matrix [4 0.5;5 7;6 8;7 9] and the final result
> should be 9. Is this possible to do in matlab?

Of course...

Solution in steps for pedagogical purposes....look up "logical
addressing" in "Getting Started" section for particulars.

 >> A=[0 0.5;1 3;2 4;3 1; 4 0.5;5 7;6 8;7 9;8 10;9 3;10 13];
 >> xmin=3.5;xmax=7.2;
 >> A(:,1)>=xmin & A(:,1)<=xmax
ans =
      0
      0
      0
      0
      1
      1
      1
      1
      0
      0
      0
 >> A(A(:,1)>=xmin & A(:,1)<=xmax,2)
ans =
     0.5000
     7.0000
     8.0000
     9.0000
 >> max(A(A(:,1)>=xmin & A(:,1)<=xmax,2))
ans =
      9
 >>

--

Subject: matrix manipulation-maximum value

From: antonio ferreira

Date: 24 Apr, 2011 18:44:06

Message: 4 of 4

dpb <none@non.net> wrote in message <ip1q7d$smv$1@speranza.aioe.org>...
> On 4/24/2011 12:55 PM, antonio ferreira wrote:
> > Hi all. I have a very simple matrix A=[0 0.5;1 3;2 4;3 1; 4 0.5;5 7;6
> > 8;7 9;8 10;9 3;10 13].
> > As you can see the first column values are always growing.
>
> ...red herring...like the superfluous information in the elementary
> mathbook.
>
>
> My objective
> > is to compute the maximum value in the second column that corresponds to
> > the range 3.5 to 7.2 in the first column. In this case matlab should
> > only consider the sub matrix [4 0.5;5 7;6 8;7 9] and the final result
> > should be 9. Is this possible to do in matlab?
>
> Of course...
>
> Solution in steps for pedagogical purposes....look up "logical
> addressing" in "Getting Started" section for particulars.
>
> >> A=[0 0.5;1 3;2 4;3 1; 4 0.5;5 7;6 8;7 9;8 10;9 3;10 13];
> >> xmin=3.5;xmax=7.2;
> >> A(:,1)>=xmin & A(:,1)<=xmax
> ans =
> 0
> 0
> 0
> 0
> 1
> 1
> 1
> 1
> 0
> 0
> 0
> >> A(A(:,1)>=xmin & A(:,1)<=xmax,2)
> ans =
> 0.5000
> 7.0000
> 8.0000
> 9.0000
> >> max(A(A(:,1)>=xmin & A(:,1)<=xmax,2))
> ans =
> 9
> >>
>
> --
>

Right...thanks

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