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

