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:
Manipulating and Indexing a matrix with logic - Need Help

Subject: Manipulating and Indexing a matrix with logic - Need Help

From: michael

Date: 15 Jul, 2010 19:59:04

Message: 1 of 5

My problem is this:

I have a large array (say 200 x 6). I would like to:

1. For all rows greater than x(insert #) in column 1, and all rows greater than y(#) in column 2,

(of those which satisfy both conditions)

2. find the row that has the minimum value for column 3 (of all the rows that pass the prev criteria)

3. For the row selected, read information from columns 4 and 5

Subject: Manipulating and Indexing a matrix with logic - Need Help

From: Sean

Date: 15 Jul, 2010 20:07:04

Message: 2 of 5

"michael " <mkinn1@comcast.net> wrote in message <i1npa8$ijg$1@fred.mathworks.com>...
> My problem is this:
>
> I have a large array (say 200 x 6). I would like to:
>
> 1. For all rows greater than x(insert #) in column 1, and all rows greater than y(#) in column 2,
>
> (of those which satisfy both conditions)
>
> 2. find the row that has the minimum value for column 3 (of all the rows that pass the prev criteria)
>
> 3. For the row selected, read information from columns 4 and 5

%%% One way
x = [1:10]';
y = randperm([10])';
z = rand(10,1);

min(z(x(x>5)&y(y>5)))

Subject: Manipulating and Indexing a matrix with logic - Need Help

From: Sean

Date: 15 Jul, 2010 20:13:20

Message: 3 of 5

"Sean " <sean.dewolski@nospamplease.umit.maine.edu> wrote in message
> %%% One way
> x = [1:10]';
> y = randperm([10])';
> z = rand(10,1);
>
> min(z(x(x>5)&y(y>5)))

One small mistake here; should read:
  min(z((x>5)&(y>5)))

Subject: Manipulating and Indexing a matrix with logic - Need Help

From: dpb

Date: 15 Jul, 2010 20:11:15

Message: 4 of 5

michael wrote:
> My problem is this:
>
> I have a large array (say 200 x 6). I would like to:
>
> 1. For all rows greater than x(insert #) in column 1, and all rows
> greater than y(#) in column 2,
>
> (of those which satisfy both conditions)
>
> 2. find the row that has the minimum value for column 3 (of all the rows
> that pass the prev criteria)
>
> 3. For the row selected, read information from columns 4 and 5

200x6 is actually a quite small array, but... :)

In steps, make as much more concise as you desire...

S = A(A(:,1)>x & A(:,2)>y; :);
[mins,idx] = min(S(:,3));
V = [S(idx,4) S(idx,5)];

Salt to suit...

--

Subject: Manipulating and Indexing a matrix with logic - Need Help

From: michael

Date: 15 Jul, 2010 20:52:04

Message: 5 of 5

Thanks for your responses, guys. I ended up using the one from dpb. Everything is working great.

the one syntax error is is should be:

S = A(A(:,1)>x & A(:,2)>y, :);
                                     |
S = A(A(:,1)>x & A(:,2)>y; :);

Thanks again!

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